[RTEMS Project] #2879: src/cpukit/libdebugger/rtems-debugger-server.c: four problems

RTEMS trac trac at rtems.org
Sun Jul 16 23:41:38 UTC 2017


#2879: src/cpukit/libdebugger/rtems-debugger-server.c: four problems
-----------------------------+--------------------------
 Reporter:  David Binderman  |       Owner:  Chris Johns
     Type:  defect           |      Status:  accepted
 Priority:  normal           |   Milestone:  4.12.0
Component:  General          |     Version:  4.11
 Severity:  normal           |  Resolution:
 Keywords:                   |
-----------------------------+--------------------------

Old description:

> 1.
>
> src/cpukit/libdebugger/rtems-debugger-server.c:1306]: (style) Redundant
> condition: extended. '!extended || (extended && check_pid(pid))' is
> equivalent to '!extended || check_pid(pid)'
>
> Suggest simplify.
>
> 2.
>
> src/cpukit/libdebugger/rtems-debugger-server.c:1858]: (warning) Possible
> null pointer dereference: rtems_debugger
>
> Source code is
>
>   if (r < 0) {
>     rtems_printf(printer, "error: rtems-db: remote begin: %s: %s\n",
>                  rtems_debugger->remote->name, strerror(errno));
>     free(rtems_debugger);
>     rtems_debugger = NULL;
>   }
>
>   /*
>    * Reset at the end of the session.
>    */
>   rtems_debugger->flags = 0;
>
> Suggest adding return -1 inside the if.
>
> 3.
>
> src/cpukit/libdebugger/rtems-debugger-server.c:906]: (style) Redundant
> condition: extended. '!extended || (extended && check_pid(pid))' is
> equivalent to '!extended || check_pid(pid)'
>
> Duplicate.
>
> 4.
>
> src/cpukit/libdebugger/rtems-debugger-server.c:956]: (warning) Char
> literal compared with pointer 'p'. Did you intend to dereference it?
>
> Source code is
>
>   while (p != NULL && p != '\0') {
>
> Maybe better code
>
>   while (p != NULL && *p != '\0') {

New description:

 1.

 {{{
 src/cpukit/libdebugger/rtems-debugger-server.c:1306]: (style) Redundant
 condition: extended. '!extended || (extended && check_pid(pid))' is
 equivalent to '!extended || check_pid(pid)'
 }}}

 Suggest simplify.

 2.

 {{{
 src/cpukit/libdebugger/rtems-debugger-server.c:1858]: (warning) Possible
 null pointer dereference: rtems_debugger
 }}}

 Source code is

 {{{
   if (r < 0) {
     rtems_printf(printer, "error: rtems-db: remote begin: %s: %s\n",
                  rtems_debugger->remote->name, strerror(errno));
     free(rtems_debugger);
     rtems_debugger = NULL;
   }

   /*
    * Reset at the end of the session.
    */
   rtems_debugger->flags = 0;
 }}}

 Suggest adding `return -1` inside the `if`.

 3.

 {{{
 src/cpukit/libdebugger/rtems-debugger-server.c:906]: (style) Redundant
 condition: extended. '!extended || (extended && check_pid(pid))' is
 equivalent to '!extended || check_pid(pid)'
 }}}

 Duplicate.

 4.

 {{{
 src/cpukit/libdebugger/rtems-debugger-server.c:956]: (warning) Char
 literal compared with pointer 'p'. Did you intend to dereference it?
 }}}

 Source code is

 {{{
   while (p != NULL && p != '\0') {
 }}}

 Maybe better code

 {{{
   while (p != NULL && *p != '\0') {
 }}}

--

Comment (by Chris Johns):

 Update formatting to show the code fragments.

--
Ticket URL: <http://devel.rtems.org/ticket/2879#comment:3>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list