#2405 closed defect (fixed)

CppCheck errors being reported throughout the code

Reported by: Martin Galvan Owned by: Martin Galvan <martin.galvan@…>
Priority: normal Milestone: 4.11.1
Component: unspecified Version: 4.11
Severity: normal Keywords:
Cc: Joel Sherrill, daniel.gutson@… Blocked By:
Blocking:

Description

I performed a run of cppcheck --enable-all on the git master and the following items were reported as 'error':

[c/src/lib/libbsp/shared/umon/umon.h:21]: (error) Invalid number of character ({) when these macros are defined: '__cplusplus'.
[cpukit/libmisc/dumpbuf/dumpbuf.c:69]: (error) Undefined behavior: Variable 'line_buffer' is used as parameter and destination in s[n]printf().
[cpukit/libmisc/dumpbuf/dumpbuf.c:76]: (error) Undefined behavior: Variable 'line_buffer' is used as parameter and destination in s[n]printf().
[cpukit/libnetworking/rtems/rtems_dhcp.c:401]: (error) Common realloc mistake: 'dhcp_hostname' nulled but not freed upon failure
[cpukit/posix/include/rtems/posix/ptimer.h:33]: (error) Invalid number of character ({) when these macros are defined: '__cplusplus'.
[cpukit/rtems/include/rtems/rtems/dpmemimpl.h:104]: (error) Invalid number of character ({) when these macros are defined: '__cplusplus'.
[tools/cpu/nios2/memory.c:99]: (error) Uninitialized variable: memory
[tools/cpu/nios2/ptf.c:582]: (error) Memory leak: new_prefix

Notice I ran cppcheck mostly on the modules I'm currently using (that means most BSPs weren't checked). Some other errors may show up when running it on the entire source.

Change History (8)

comment:1 Changed on 09/01/15 at 21:41:51 by Joel Sherrill

I posted proposed fixes for all of these except the rtems_dhcp.c one. Please review and let me know.

comment:2 in reply to:  1 Changed on 09/01/15 at 22:02:50 by Martin Galvan

Replying to joel.sherrill:

I posted proposed fixes for all of these except the rtems_dhcp.c one. Please review and let me know.

It looks fine to me. However, if you don't mind me asking:

1) What's wrong with the rtems_dhcp fix?
2) In nios2/ptf.c I added a check for the return value of malloc, but the patch you sent only adds the missing free. Was there something wrong with that check?

Thanks a lot!

comment:3 Changed on 09/03/15 at 16:27:59 by Martin Galvan <martin.galvan@…>

Owner: set to Martin Galvan <martin.galvan@…>
Resolution: fixed
Status: newclosed

In c62129c5bcaf2b10baf7d3e1b856c81e343c4b5b/rtems:

cpukit/libnetworking/rtems/rtems_dhcp.c: Fix leak on realloc failure for dhcp_hostname.

Closes #2405.

comment:4 Changed on 09/03/15 at 16:28:29 by Martin Galvan <martin.galvan@…>

In c83bad2fc452169303f9fc58628841e325e033dd/rtems:

cpukit/libnetworking/rtems/rtems_dhcp.c: Fix leak on realloc failure for dhcp_hostname.

Closes #2405.

comment:5 Changed on 09/03/15 at 17:33:38 by Martin Galvan <martin.galvan@…>

In cc93c83e00df36124781c9a5bbe213c7c0715fd8/rtems:

cpukit/libmisc/dumpbuf/dumpbuf.c: Fix undefined behavior for sprintf()

I also used the 'n' versions of the string functions, #define'd magic numbers
and added a few comments.

Updates #2405.

comment:6 Changed on 09/03/15 at 17:34:15 by Martin Galvan <martin.galvan@…>

In 9e2197d5d7ce759f77717d51063d7bfdb340254c/rtems:

cpukit/libmisc/dumpbuf/dumpbuf.c: Fix undefined behavior for sprintf()

I also used the 'n' versions of the string functions, #define'd magic numbers
and added a few comments.

Updates #2405.

comment:7 Changed on 09/03/15 at 20:42:52 by Martin Galvan <martin.galvan@…>

In 28a870c47f66d946a6d94887120432be37441cdb/rtems:

cpukit/libnetworking/rtems/rtems_dhcp.c: Fix compilation error

Apparently 'free' is defined as a macro which takes two arguments and calls
rtems_bsdnet_free. When fixing #2405 I added a missing 'free' but didn't notice
it was non-standard.

Closes #2410.

comment:8 Changed on 09/03/15 at 20:43:14 by Martin Galvan <martin.galvan@…>

In efb798e16ef9719b63e428e55eb039ffc79d11a0/rtems:

cpukit/libnetworking/rtems/rtems_dhcp.c: Fix compilation error

Apparently 'free' is defined as a macro which takes two arguments and calls
rtems_bsdnet_free. When fixing #2405 I added a missing 'free' but didn't notice
it was non-standard.

Closes #2410.

Note: See TracTickets for help on using tickets.