Skip to content

Commit

Permalink
Fixed a couple of gcc warnings
Browse files Browse the repository at this point in the history
In cups/dest.c:

    dest.c:1830:21: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
     1733 |       DEBUG_printf(("1cupsGetNamedDest: Using name=\"%s\"...", name));
	  |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is really true, and gcc was smart enough to deduct it from context.
Obviously, we meant to print dest_name here.

In cgi-bin/search.c:

    search.c:191:29: warning: pointer ‘s’ may be used after ‘realloc’ [-Wuse-after-free]
      191 |         sptr = temp + (sptr - s);
	  |                       ~~~~~~^~~~

The code is correct, but too hard for gcc to analyze. So code simplified
a bit to make compiler happy.
  • Loading branch information
alexpevzner committed Feb 8, 2024
1 parent 29874c3 commit 72b2171
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cgi-bin/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ cgiCompileSearch(const char *query) /* I - Query string */
* Expand the RE string buffer...
*/

char *temp; /* Temporary string pointer */
char *temp; /* Temporary string pointer */
size_t soff = sptr - s; /* Save offset to use after realloc */


slen = wlen + 128;
Expand All @@ -188,7 +189,7 @@ cgiCompileSearch(const char *query) /* I - Query string */
return (NULL);
}

sptr = temp + (sptr - s);
sptr = temp + soff;
s = temp;
}

Expand Down
2 changes: 1 addition & 1 deletion cups/dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ cupsGetNamedDest(http_t *http, // I - Connection to server or @code CUPS_HTT
DEBUG_puts("1cupsGetNamedDest: Asking server for default printer...");
}
else
DEBUG_printf("1cupsGetNamedDest: Using name=\"%s\"...", name);
DEBUG_printf("1cupsGetNamedDest: Using name=\"%s\"...", dest_name);
}

//
Expand Down

0 comments on commit 72b2171

Please sign in to comment.