Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Fix warning: ‘memset’ used with length equal to number of elements wa…
Browse files Browse the repository at this point in the history
…rning

Fix similar warnings to these by including the element size into total size
calculation.

src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp: In function ‘int main(int, char**)’:
src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp:89:31: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
     memset(NewValue,0,BUF_SIZE);
  • Loading branch information
franksinankaya committed Feb 6, 2019
1 parent cdcb0d7 commit dfaf7be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int __cdecl main(int argc, char **argv)
free(PrintResult);
}

memset(name, '\0', 128);
memset(name, '\0', 128 * sizeof(name[0]));
}

PAL_Terminate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int __cdecl main(int argc, char *argv[])

/* Initialize the buffer.
*/
memset( szDirectory, '\0', 256 );
memset( szDirectory, '\0', 256 * sizeof(szDirectory[0]) );

/* Change the current working directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int __cdecl main(int argc, char *argv[])

/* Initialize the buffer.
*/
memset(szDirectory, '\0', 256);
memset(szDirectory, '\0', 256 * sizeof(szDirectory[0]));

/* Create the path to the next level of directory to create.
*/
Expand Down
24 changes: 12 additions & 12 deletions src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int test1(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -69,7 +69,7 @@ int test2(int num, ...)
va_list TheList;
va_start(TheList,num);

memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -106,7 +106,7 @@ int test3(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
Expand Down Expand Up @@ -144,7 +144,7 @@ int test4(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
Expand Down Expand Up @@ -182,7 +182,7 @@ int test5(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -222,7 +222,7 @@ int test6(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -264,7 +264,7 @@ int test7(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -307,7 +307,7 @@ int test8(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -351,7 +351,7 @@ int test9(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
Expand Down Expand Up @@ -393,7 +393,7 @@ int test10(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
Expand Down Expand Up @@ -435,7 +435,7 @@ int test11(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down Expand Up @@ -505,7 +505,7 @@ int test12(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
memset( OutBuffer, 0, 1024 );
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );

ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int __cdecl main(int argc, char *argv[])
"the variable PALTEST.\n");
}

memset(NewValue,0,BUF_SIZE);
memset(NewValue,0,BUF_SIZE * sizeof(NewValue[0]));

/* Grab the Environment variable we just set */
if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0)
Expand Down Expand Up @@ -122,7 +122,7 @@ int __cdecl main(int argc, char *argv[])
"the variable PALTEST.\n");
}

memset(NewValue,0,BUF_SIZE);
memset(NewValue,0,BUF_SIZE*sizeof(NewValue[0]));

/* Grab the Environment variable we just set, ensure that it's
empty now.
Expand Down

0 comments on commit dfaf7be

Please sign in to comment.