https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83842
Bug ID: 83842 Summary: extend -Wmemset-elt-size to memcpy and memmove Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The -Wmemset-elt-size warning is helpful in pointing out the mistake of passing the number of array elements to memset rather than the number of bytes. The same mistake can happen when calling memcpy and memmove. It would be useful to extend the -Wmemset-elt-size to those functions as well (either under the same option or under a new one). $ cat z.c && gcc -S -Wall z.c int a[2]; void f (void) { __builtin_memset (a, 0, 2); // -Wmemset-elt-size (good) } void g (const int *p) { __builtin_memcpy (a, p, 2); // missing -Wmemcpy-elt-size } void h0 (void) { __builtin_memmove (a, &a[1], 2); // missing -Wmemmove-elt-size } void h1 (void) { __builtin_memmove (&a[1], a, 2); // missing -Wmemmove-elt-size } z.c: In function ‘f’: z.c:5:3: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size] __builtin_memset (a, 0, 2); // -Wmemset-elt-size (good) ^~~~~~~~~~~~~~~~