Skip to content

Commit

Permalink
cgps: fixes compiler warning.
Browse files Browse the repository at this point in the history
The fix to avoid writing into a read-only buffer copies a const char
pointer to a non-const char pointer, provoking a warning.  For some
reason, the old code failed to get a similar warning from the cast,
which would have caught the original bug.

This fix just adds a const char variable to accept the pointer.

TESTED:
Now cgps builds without warning, and still works.
  • Loading branch information
fhgwright committed Mar 8, 2018
1 parent 89251b8 commit 75d16ca
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cgps.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,12 @@ static void update_gps_panel(struct gps_data_t *gpsdata)

if ( raw_flag) {
/* Be quiet if the user requests silence. */
if (!silent_flag && (s = gps_data(gpsdata)) != NULL) {
const char *sr;
if (!silent_flag && (sr = gps_data(gpsdata)) != NULL) {
char *p, *pe;

/* make a copy of the const char *, then trim trailing spaces */
p = strdup(s);
p = strdup(sr);
if ( NULL != p ) {
pe = p + strlen(p);
for ( ; --pe > p && isspace((int) *pe); *pe = '\0')
Expand Down

0 comments on commit 75d16ca

Please sign in to comment.