diff options
author | Gary E. Miller <gem@rellim.com> | 2018-02-14 14:01:58 -0800 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2018-02-14 14:01:58 -0800 |
commit | 647194f9090448ab861e8729ac032f02870eb44c (patch) | |
tree | 3e3aee2f04b5e75ca0f88285bfabf6968d6e940a | |
parent | f9082ceb1dddf3a47c8807651cd25cbdd58af7d0 (diff) | |
download | gpsd-647194f9090448ab861e8729ac032f02870eb44c.tar.gz |
cgps: Stop writing into a const char buffer!
-rw-r--r-- | cgps.c | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -711,12 +711,22 @@ static void update_gps_panel(struct gps_data_t *gpsdata) } - /* Be quiet if the user requests silence. */ - if (!silent_flag && raw_flag && (s = (char *)gps_data(gpsdata)) != NULL) { - char *p; - for (p = s + strlen(s); --p > s && isspace((unsigned char) *p); *p = '\0') - ; - (void)wprintw(messages, "%s\n", s); + if ( raw_flag) { + /* Be quiet if the user requests silence. */ + if (!silent_flag && (s = gps_data(gpsdata)) != NULL) { + char *p, *pe; + + /* make a copy of the const char *, then trim trailing spaces */ + p = strdup(s); + if ( NULL != p ) { + pe = p + strlen(p); + for ( ; --pe > p && isspace((int) *pe); *pe = '\0') + ; + (void)wprintw(messages, "%s\n", p); + free(p); + } + } + (void)wrefresh(messages); } /* Reset the status_timer if the state has changed. */ @@ -727,9 +737,6 @@ static void update_gps_panel(struct gps_data_t *gpsdata) (void)wrefresh(datawin); (void)wrefresh(satellites); - if (raw_flag) { - (void)wrefresh(messages); - } } static void usage(char *prog) |