[GRASS-dev] [GRASS GIS] #1324: DebCheck QA: Undefined behaviour- variable is used wrong in call to sprintf or snprintf

#1324: DebCheck QA: Undefined behaviour- variable is used wrong in call to sprintf
or snprintf
-----------------------+----------------------------------------------------
Reporter: hamish | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: Compiling | Version: 6.4.0
Platform: Linux | Cpu: Unspecified
-----------------------+----------------------------------------------------
Keywords:
d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c,
lib/vector/Vlib/dbcolumns.c, v.digit, v.external

-----------------------+----------------------------------------------------
Hi,

Debian's run of the Cpp check tool automatically found a number of C-code
errors (or potential errors) which need to be reviewed by hand. See grass-
dev ML thread of 13 Jan 2011.

about:
''Cppcheck is a command-line tool that tries to detect bugs that your
C/C++ compiler doesn't see. It is versatile, and can check non-standard
code including various compiler extensions, inline assembly code, etc. Its
internal preprocessor can handle includes, macros, and several
preprocessor commands. While Cppcheck is highly configurable, you can
start using it just by giving it a path to the source code.''

  http://www.linuxjournal.com/content/daca-could-mean-less-bugs-debian
the list of probably-bugs in the 6.4.0 C/C++ code:
   http://qa.debian.org/daca/cppcheck/squeeze/grass_6.4.0~rc6+42329-3.html
CLI analysis program (not Debian specific):
   http://cppcheck.wiki.sourceforge.net

I have split those 154 hits into 16 classes, and will report each class in
an individual bug report.

Run against releasebranch6_4 r42329 (including all patches up to, but not
beyond, 6.4.0-final)

----

This bug report is for: '''Undefined behaviour- variable is used wrong in
call to sprintf or snprintf'''

  * ./display/d.barscale/main.c:171 [error] - Undefined behaviour: cmdbuf
is used wrong in call to sprintf or snprintf. Quote: If copying takes
place between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.barscale/main.c:172 [error] - Undefined behaviour: cmdbuf
is used wrong in call to sprintf or snprintf. Quote: If copying takes
place between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:382 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:383 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:384 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:385 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:386 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:387 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.text.new/main.c:388 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.vect/label.c:97 [error] - Undefined behaviour: text is used
wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.vect/label.c:99 [error] - Undefined behaviour: text is used
wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.zoom/print.c:106 [error] - Undefined behaviour: buffer is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.zoom/print.c:113 [error] - Undefined behaviour: buffer is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./display/d.zoom/print.c:120 [error] - Undefined behaviour: buffer is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./lib/symbol/read.c:345 [error] - Undefined behaviour: buf is used
wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./lib/symbol/read.c:429 [error] - Undefined behaviour: buf is used
wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./lib/vector/Vlib/dbcolumns.c:79 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./lib/vector/Vlib/dbcolumns.c:139 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./lib/vector/Vlib/dbcolumns.c:202 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./vector/v.digit/i_face.c:91 [error] - Undefined behaviour: val is used
wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./vector/v.digit/i_face.c:93 [error] - Undefined behaviour: val is used
wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./vector/v.external/main.c:53 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.
  * ./vector/v.external/main.c:55 [error] - Undefined behaviour: buf is
used wrong in call to sprintf or snprintf. Quote: If copying takes place
between objects that overlap as a result of a call to sprintf() or
snprintf(), the results are undefined.

Modules: d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c,
lib/vector/Vlib/dbcolumns.c, v.digit, v.external

thanks,
Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1324&gt;
GRASS GIS <http://grass.osgeo.org>

#1324: DebCheck QA: Undefined behaviour- variable is used wrong in call to sprintf
or snprintf
-----------------------+----------------------------------------------------
Reporter: hamish | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: Compiling | Version: 6.4.0
Platform: Linux | Cpu: Unspecified
-----------------------+----------------------------------------------------
Keywords:
d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c,
lib/vector/Vlib/dbcolumns.c, v.digit, v.external

-----------------------+----------------------------------------------------

Comment(by marisn):

Hamish your bug report is useless, as many of those places are already
fixed. When doing code quality analysis, please, use most recent code
version.

https://trac.osgeo.org/grass/changeset/44984

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1324#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1324: DebCheck QA: Undefined behaviour- variable is used wrong in call to sprintf
or snprintf
-----------------------------------------------------------------------------------------------------------------+
Reporter: hamish | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: Compiling | Version: 6.4.0
Keywords: d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c, lib/vector/Vlib/dbcolumns.c, v.external | Platform: Linux
      Cpu: Unspecified |
-----------------------------------------------------------------------------------------------------------------+
Changes (by hamish):

  * keywords: d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c,
lib/vector/Vlib/dbcolumns.c, v.digit, v.external =>
               d.barscale, d.text.new, d.vect, d.zoom,
               lib/symbol/read.c,
               lib/vector/Vlib/dbcolumns.c, v.external

Comment:

Replying to [comment:1 marisn]:
> Hamish your bug report is useless, as many of those places are already
fixed.

Not useless, just slightly out of date (c. Sept 2010). Most of the
problems identified in the overall check are still in the code.

Please note which ones have been fixed so we can cross them off the list.

thanks for fixing v.digit/i_face.c:
> https://trac.osgeo.org/grass/changeset/44984

how far down the list did you get?

> When doing code quality analysis, please, use most recent code version.

I simply pass on the latest results from the Debian system; I had checked
for a newer analysis from the Debian/unstable repo but that hasn't been
run yet. Manually running the cppcheck program ourselves means we could
run it against grass/trunk- feel free to do that if you like.

Hamish

ps- positive energy is contagious, as is negative energy. But positive
energy pulls volunteers in while negative energy drives volunteers away.
Suggestions for improvements and pointing out mistakes are always welcome,
but being rude kills motivation.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1324#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1324: DebCheck QA: Undefined behaviour- variable is used wrong in call to sprintf
or snprintf
-----------------------------------------------------------------------------------------------------------------+
Reporter: hamish | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: Compiling | Version: 6.4.0
Keywords: d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c, lib/vector/Vlib/dbcolumns.c, v.external | Platform: Linux
      Cpu: Unspecified |
-----------------------------------------------------------------------------------------------------------------+

Comment(by hellik):

Replying to [comment:2 hamish]:
>[...]
> ps- positive energy is contagious, as is negative energy. But positive
energy pulls volunteers in while negative energy drives volunteers away.
Suggestions for improvements and pointing out mistakes are always welcome,
but being rude kills motivation.

+1

Helmut

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1324#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1324: DebCheck QA: Undefined behaviour- variable is used wrong in call to sprintf
or snprintf
-----------------------------------------------------------------------------------------------------------------+
Reporter: hamish | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: Compiling | Version: 6.4.0
Keywords: d.barscale, d.text.new, d.vect, d.zoom, lib/symbol/read.c, lib/vector/Vlib/dbcolumns.c, v.external | Platform: Linux
      Cpu: Unspecified |
-----------------------------------------------------------------------------------------------------------------+

Comment(by hamish):

d.barscale fixed in devbr6 with r56877. n/a to trunk's d.barscale.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1324#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>