summaryrefslogtreecommitdiff
path: root/cgps.c
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2018-02-14 14:01:58 -0800
committerGary E. Miller <gem@rellim.com>2018-02-14 14:01:58 -0800
commit647194f9090448ab861e8729ac032f02870eb44c (patch)
tree3e3aee2f04b5e75ca0f88285bfabf6968d6e940a /cgps.c
parentf9082ceb1dddf3a47c8807651cd25cbdd58af7d0 (diff)
downloadgpsd-647194f9090448ab861e8729ac032f02870eb44c.tar.gz
cgps: Stop writing into a const char buffer!
Diffstat (limited to 'cgps.c')
-rw-r--r--cgps.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/cgps.c b/cgps.c
index 7c03948e..85e42414 100644
--- a/cgps.c
+++ b/cgps.c
@@ -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)