Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Incorrect usage of sizeof (used on C string pointers) #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Demonese
Copy link
Contributor

Summary:

For const char FOO[] = "foo", FOO is a C array.

But for const char* BAR = "bar", BAR is a pointer.

sizeof(BAR) always equals pointer size.

After:

const char D3D10_NOTE[] = "Most Direct3D 10 features are required. Tool only shows optional features.";
const char D3D10_NOTE1[] = "Most Direct3D 10.1 features are required. Tool only shows optional features.";
const char D3D11_NOTE[] = "Most Direct3D 11 features are required. Tool only shows optional features.";
const char D3D11_NOTE1[] = "Most Direct3D 11.1 features are required. Tool only shows optional features.";
const char D3D11_NOTE2[] = "Most Direct3D 11.2 features are required. Tool only shows optional features.";
const char D3D11_NOTE3[] = "Most Direct3D 11.3 features are required. Tool only shows optional features.";
const char D3D11_NOTE4[] = "Most Direct3D 11.x features are required. Tool only shows optional features.";
const char _10L9_NOTE[] = "Most 10level9 features are required. Tool only shows optional features.";
const char SEE_D3D10[] = "See Direct3D 10 node for device details.";
const char SEE_D3D10_1[] = "See Direct3D 10.1 node for device details.";
const char SEE_D3D11[] = "See Direct3D 11 node for device details.";
const char SEE_D3D11_1[] = "See Direct3D 11.1 node for device details.";

const char FL_NOTE[] = "This feature summary is derived from hardware feature level";

static_assert(sizeof(D3D10_NOTE) < 80, "String too long");
static_assert(sizeof(D3D10_NOTE1) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE1) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE2) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE3) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE4) < 80, "String too long");
static_assert(sizeof(_10L9_NOTE) < 80, "String too long");
static_assert(sizeof(SEE_D3D10) < 80, "String too long");
static_assert(sizeof(SEE_D3D10_1) < 80, "String too long");
static_assert(sizeof(SEE_D3D11) < 80, "String too long");
static_assert(sizeof(SEE_D3D11_1) < 80, "String too long");

Before:

const char* D3D10_NOTE = "Most Direct3D 10 features are required. Tool only shows optional features.";
const char* D3D10_NOTE1 = "Most Direct3D 10.1 features are required. Tool only shows optional features.";
const char* D3D11_NOTE = "Most Direct3D 11 features are required. Tool only shows optional features.";
const char* D3D11_NOTE1 = "Most Direct3D 11.1 features are required. Tool only shows optional features.";
const char* D3D11_NOTE2 = "Most Direct3D 11.2 features are required. Tool only shows optional features.";
const char* D3D11_NOTE3 = "Most Direct3D 11.3 features are required. Tool only shows optional features.";
const char* D3D11_NOTE4 = "Most Direct3D 11.x features are required. Tool only shows optional features.";
const char* _10L9_NOTE = "Most 10level9 features are required. Tool only shows optional features.";
const char* SEE_D3D10 = "See Direct3D 10 node for device details.";
const char* SEE_D3D10_1 = "See Direct3D 10.1 node for device details.";
const char* SEE_D3D11 = "See Direct3D 11 node for device details.";
const char* SEE_D3D11_1 = "See Direct3D 11.1 node for device details.";

const char* FL_NOTE = "This feature summary is derived from hardware feature level";

static_assert(sizeof(D3D10_NOTE) < 80, "String too long");
static_assert(sizeof(D3D10_NOTE1) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE1) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE2) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE3) < 80, "String too long");
static_assert(sizeof(D3D11_NOTE4) < 80, "String too long");
static_assert(sizeof(_10L9_NOTE) < 80, "String too long");
static_assert(sizeof(SEE_D3D10) < 80, "String too long");
static_assert(sizeof(SEE_D3D10_1) < 80, "String too long");
static_assert(sizeof(SEE_D3D11) < 80, "String too long");
static_assert(sizeof(SEE_D3D11_1) < 80, "String too long");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant