Menu

#733 history.c: 3 * bad memset size ?

v1.0 (example)
closed-fixed
nobody
None
5
2018-06-19
2017-09-02
dcb
No

history.c:310:29: warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
history.c:311:29: warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
history.c:312:29: warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

    memset(hours, '\0', sizeof(hours));
    memset(minutes, '\0', sizeof(minutes));
    memset(seconds, '\0', sizeof(seconds));

Discussion

  • Michael S.

    Michael S. - 2017-09-03

    Which version of gcc you are using ?

    I've got 4.9.2-10 and getting no compiler warnings:

    # gcc --version
    gcc (Raspbian 4.9.2-10) 4.9.2
    Copyright (C) 2014 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
    
     
  • dcb

    dcb - 2017-09-03

    Three year old compiler is very old.

    Current released version of gcc is 7.2 - I am using 8.0 (development
    snapshot).

    Suggest upgrade, if you can.

     
  • Bodo

    Bodo - 2017-09-03

    It is a bug.
    Instead of
    char* hours = myMalloc(12);
    etc use
    char hours[12];
    etc and make sure not to use free()
    or specify the size with the same #define instead of the literal 12 both for myMalloc and memset.

     
  • Michael S.

    Michael S. - 2017-09-04

    Or using 'malloc_usable_size' if available.

    My mistake. I tought, that an array had been used instead of a pointer.

     
  • Michael S.

    Michael S. - 2017-10-21

    Patch commited.

     
  • Bodo

    Bodo - 2018-06-19
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB