bugAVR Downloader/UploaDEr - Bugs: bug #35265, Findings reported by cppcheck

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #35265: Findings reported by cppcheck

Submitter:  Rene Liebscher <rliebscher>
Submitted:  Sun 08 Jan 2012 05:18:52 PM UTC
   
 
Category:  None Severity:  2 - Minor
Priority:  5 - Normal Item Group:  None
Status:  In Progress Privacy:  Public
Assigned to:  None Originator Name:  Rene Liebscher
Open/Closed:  Open Release:  None
Programmer hardware:  Device type: 

Fri 13 Jan 2012 10:22:04 PM UTC, comment #5: 

I made a first patch which replaces all usleep by microsleep and adds a file util.c which realizes microsleep either by nanosleep, usleep or by a Windows specififc function. (For the last it moved the code from ppiwin.c to util.c)

MinGW has only usleep but no nanosleep (at least configure does not find it) so I left the usleep variant in the code.

(file #24815)

Rene Liebscher <rliebscher>
Group Member
Tue 10 Jan 2012 07:18:18 AM UTC, comment #4: 


> I agree about the new implementation file.


With one exception though: avrdude.c is just too generic a
name.  That name should probably be the name of the main
(CLI) file (rather than main.c).

My suggestion is to name it util.c or such.

avrdude.h should simply combine the exported interfaces
(by libavrdude.a) from all the existing header files.  The
current header file structure is a nuisance for anyone who
wants to use the library.  If there are library-internal
interfaces that are not supposed to be exported (so they
could be easily changed between library versions), they could
go into a second header file that is only used to build the
library itself, but not going to be installed even in case
we once install the library itself.

Joerg Wunsch <joerg_wunsch>
Group administrator
Mon 09 Jan 2012 10:27:47 PM UTC, comment #3: 

OK, thanks, with the commandline, I can reproduce the
messages now.

> 'Our' usleep is the old posix usleep


You're right.  While I don't think any of the actual systems
are going to remove it in the near future, it certainly makes
sense to replace it by nanosleep().

Given that nanosleep() is quoted (in FreeBSD's manpage) to
originate in Posix.1 (IEEE Std 1003.1b-1993), are there any
actual systems around we want to be portable to (various
Linuxes, *BSD, Solaris, MacOS X) which don't have it?

I agree about the new implementation file.

Joerg Wunsch <joerg_wunsch>
Group administrator
Mon 09 Jan 2012 08:11:12 PM UTC, comment #2: 

command line was 'cppcheck --enable=all .'

cppcheck version is 'Cppcheck 1.49'

'Our' usleep is the old posix usleep (except on Windows were we have a replacement in ppiwin.c).

But: POSIX.1-2001 declares this function obsolete; use       nanosleep(2) instead.  POSIX.1-2008 removes the specification of usleep(). (see https://www.kernel.org/doc/man-pages/online/pages/man3/usleep.3.html)

So we better replace all occurrences of usleep by an own wrapper microsleep. To use nanosleep we have check it in the configure file.

I would put this wrapper in a new C-file (avrdude.c?, as we have an avrdude.h defining a usleep for Windows.) I also would move the implementations of usleep and gettimeofday from ppiwin.c to this new file as they are used not only by the parallel port programmers.

Rene Liebscher <rliebscher>
Group Member
Sun 08 Jan 2012 10:37:44 PM UTC, comment #1: 

Could you please post you commandline?

> (style) Found obsolete function 'usleep'


Maybe we should rename our usleep() into microsleep().

Joerg Wunsch <joerg_wunsch>
Group administrator
Sun 08 Jan 2012 05:18:52 PM UTC, original submission:  

When running cppcheck the following findings are reported:


[avr.c:94]: (information) The scope of the variable 'r' can be reduced
[avrftdi.c:368]: (information) The scope of the variable 'n' can be reduced
[avrftdi.c:404]: (style) Variable 'vid' is assigned a value that is never used
[avrftdi.c:404]: (style) Variable 'pid' is assigned a value that is never used
[avrftdi.c:404]: (style) Variable 'interface' is assigned a value that is never used
[avrftdi.c:404]: (style) Variable 'snfound' is assigned a value that is never used
[avrftdi.c:405]: (style) Unused variable: serial
[avrftdi.c:405]: (style) Variable 'foundsn' is assigned a value that is never used
[avrftdi.c:406]: (style) Unused variable: devlist
[avrftdi.c:407]: (style) Unused variable: devlist_ptr
[avrftdi.c:408]: (style) Unused variable: found_dev
[avrpart.c:335]: (information) The scope of the variable 'i' can be reduced
[avrpart.c:335]: (information) The scope of the variable 'j' can be reduced
[bitbang.c:499]: (information) The scope of the variable 'i' can be reduced
[bitbang.c:535]: (information) The scope of the variable 'tries' can be reduced
[bitbang.c:536]: (information) The scope of the variable 'i' can be reduced
[config_gram.c:1952]: (error) Memory leak: yyptr
[config_gram.c]: (information) Interrupted checking because of too many #ifdef configurations.
[jtagmkI.c:706]: (information) The scope of the variable 'b' can be reduced
[jtagmkII.c:486]: (style) Variable 'checksum' is assigned a value that is never used
[jtagmkII.c:2561]: (style) Variable 'config0' is assigned a value that is never used
[jtagmkII.c:2561]: (style) Variable 'config1' is assigned a value that is never used
[jtagmkII.c:2470]: (information) The scope of the variable 'clk' can be reduced
[jtagmkII.c:2561]: (information) The scope of the variable 'config1' can be reduced
[lexer.c:377]: (style) struct or union member 'yy_trans_info::yy_verify' is never used
[lexer.c:378]: (style) struct or union member 'yy_trans_info::yy_nxt' is never used
[lexer.c]: (information) Interrupted checking because of too many #ifdef configurations.
[par.c:49]: (style) struct or union member 'ppipins_t::pin' is never used
[ser_posix.c:197]: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function
[ser_win32.c:231]: (information) The scope of the variable 'c' can be reduced
[ser_win32.c:285]: (information) The scope of the variable 'c' can be reduced
[stk500.c:751]: (style) Variable 'flash' is assigned a value that is never used
[stk500.c:413]: (information) The scope of the variable 'rc' can be reduced
[stk500.c:992]: (information) The scope of the variable 'fosc' can be reduced
[stk500.c:996]: (information) The scope of the variable 'idx' can be reduced
[stk500v2.c:1721]: (style) Variable 'hiaddr' is assigned a value that is never used
[stk500v2.c:1854]: (style) Variable 'hiaddr' is assigned a value that is never used
[stk500v2.c:2205]: (information) The scope of the variable 'fosc' can be reduced
[stk500v2.c:2210]: (information) The scope of the variable 'idx' can be reduced
[term.c:210]: (style) Variable 'i' is assigned a value that is never used
[term.c:527]: (information) The scope of the variable 'i' can be reduced
[update.c:39]: (information) The scope of the variable 'c' can be reduced
[update.c:207]: (information) The scope of the variable 'vsize' can be reduced
[usb_libusb.c:389]: (information) The scope of the variable 'i' can be reduced
[wiring.c:154]: (information) The scope of the variable 'timetosnooze' can be reduced


Also there are a lot of findings "(style) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function", which I filtered out.

Some errors were already removed in svn revision 1035.

Rene Liebscher <rliebscher>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #24815:  util.c added by rliebscher (4KiB - text/x-csrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Posted a comment)
  • -email is unavailable- added by rliebscher (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-01-13 rliebscher Attached File- Added util.c, #24815
        StatusNone In Progress

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code