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

Commit b530527

Browse files
Fix warning: ‘memset’ used with length equal to number of elements warning
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);
1 parent 8c44e90 commit b530527

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int __cdecl main(int argc, char **argv)
6969
free(PrintResult);
7070
}
7171

72-
memset(name, '\0', 128);
72+
memset(name, '\0', 128 * sizeof(name[0]));
7373
}
7474

7575
PAL_Terminate();

src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int __cdecl main(int argc, char *argv[])
6262

6363
/* Initialize the buffer.
6464
*/
65-
memset( szDirectory, '\0', 256 );
65+
memset( szDirectory, '\0', 256 * sizeof(szDirectory[0]) );
6666

6767
/* Change the current working directory.
6868
*/

src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int __cdecl main(int argc, char *argv[])
6161

6262
/* Initialize the buffer.
6363
*/
64-
memset(szDirectory, '\0', 256);
64+
memset(szDirectory, '\0', 256 * sizeof(szDirectory[0]));
6565

6666
/* Create the path to the next level of directory to create.
6767
*/

src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int test1(int num, ...)
2525
int ReturnResult;
2626
va_list TheList;
2727
va_start(TheList,num);
28-
memset( OutBuffer, 0, 1024 );
28+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
2929

3030
ReturnResult = FormatMessage(
3131
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -69,7 +69,7 @@ int test2(int num, ...)
6969
va_list TheList;
7070
va_start(TheList,num);
7171

72-
memset( OutBuffer, 0, 1024 );
72+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
7373

7474
ReturnResult = FormatMessage(
7575
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -106,7 +106,7 @@ int test3(int num, ...) {
106106
int ReturnResult;
107107
va_list TheList;
108108
va_start(TheList,num);
109-
memset( OutBuffer, 0, 1024 );
109+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
110110
ReturnResult = FormatMessage(
111111
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
112112
TheString, /* message source */
@@ -144,7 +144,7 @@ int test4(int num, ...) {
144144
int ReturnResult;
145145
va_list TheList;
146146
va_start(TheList,num);
147-
memset( OutBuffer, 0, 1024 );
147+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
148148
ReturnResult = FormatMessage(
149149
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
150150
TheString, /* message source */
@@ -182,7 +182,7 @@ int test5(int num, ...)
182182
int ReturnResult;
183183
va_list TheList;
184184
va_start(TheList,num);
185-
memset( OutBuffer, 0, 1024 );
185+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
186186

187187
ReturnResult = FormatMessage(
188188
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -222,7 +222,7 @@ int test6(int num, ...) {
222222
int ReturnResult;
223223
va_list TheList;
224224
va_start(TheList,num);
225-
memset( OutBuffer, 0, 1024 );
225+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
226226

227227
ReturnResult = FormatMessage(
228228
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -264,7 +264,7 @@ int test7(int num, ...)
264264
int ReturnResult;
265265
va_list TheList;
266266
va_start(TheList,num);
267-
memset( OutBuffer, 0, 1024 );
267+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
268268

269269
ReturnResult = FormatMessage(
270270
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -307,7 +307,7 @@ int test8(int num, ...)
307307
int ReturnResult;
308308
va_list TheList;
309309
va_start(TheList,num);
310-
memset( OutBuffer, 0, 1024 );
310+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
311311

312312
ReturnResult = FormatMessage(
313313
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -351,7 +351,7 @@ int test9(int num, ...) {
351351
int ReturnResult;
352352
va_list TheList;
353353
va_start(TheList,num);
354-
memset( OutBuffer, 0, 1024 );
354+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
355355
ReturnResult = FormatMessage(
356356
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
357357
TheString, /* message source */
@@ -393,7 +393,7 @@ int test10(int num, ...)
393393
int ReturnResult;
394394
va_list TheList;
395395
va_start(TheList,num);
396-
memset( OutBuffer, 0, 1024 );
396+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
397397
ReturnResult = FormatMessage(
398398
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
399399
TheString, /* message source */
@@ -435,7 +435,7 @@ int test11(int num, ...)
435435
int ReturnResult;
436436
va_list TheList;
437437
va_start(TheList,num);
438-
memset( OutBuffer, 0, 1024 );
438+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
439439

440440
ReturnResult = FormatMessage(
441441
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -505,7 +505,7 @@ int test12(int num, ...)
505505
int ReturnResult;
506506
va_list TheList;
507507
va_start(TheList,num);
508-
memset( OutBuffer, 0, 1024 );
508+
memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
509509

510510
ReturnResult = FormatMessage(
511511
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */

src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int __cdecl main(int argc, char *argv[])
8686
"the variable PALTEST.\n");
8787
}
8888

89-
memset(NewValue,0,BUF_SIZE);
89+
memset(NewValue,0,BUF_SIZE * sizeof(NewValue[0]));
9090

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

125-
memset(NewValue,0,BUF_SIZE);
125+
memset(NewValue,0,BUF_SIZE*sizeof(NewValue[0]));
126126

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

0 commit comments

Comments
 (0)