rgamble / libcsv

Fast and flexible CSV library written in pure ANSI C that can read and write CSV data.
GNU Lesser General Public License v2.1
181 stars 40 forks source link

-Wunused-but-set-variable #4

Closed bobhairgrove closed 7 years ago

bobhairgrove commented 7 years ago

There is an "unused but set variable" warning from gcc when compiling libcsv:

libcsv.c: In function ‘csv_fini’:
libcsv.c:163:7: warning: variable ‘pstate’ set but not used [-Wunused-but-set-variable]
   int pstate = p->pstate;

If you could fix this, it will compile without any warnings.

Suggestion: go to line 171 in libcsv.c and change this line:

  if (p->pstate == FIELD_BEGUN && p->quoted && p->options & CSV_STRICT && p->options & CSV_STRICT_FINI) {

to this:

  if (pstate == FIELD_BEGUN && p->quoted && p->options & CSV_STRICT && p->options & CSV_STRICT_FINI) {

I ran it through the preprocessor by doing gcc -E -o libcsv_pre.c libcsv.c and compared the preprocessed source with the original. Indeed, pstate is set several times in code generated by macros, so just removing line 163 isn't the best option. However, its value is never read, AFAICT.

Did you originally intend to set the parser's p->pstate from the local variable before returning, or before calling one of the callbacks?

rgamble commented 7 years ago

Fixed in merged commit 44f79cf4.