From 647194f9090448ab861e8729ac032f02870eb44c Mon Sep 17 00:00:00 2001 From: "Gary E. Miller" Date: Wed, 14 Feb 2018 14:01:58 -0800 Subject: cgps: Stop writing into a const char buffer! --- cgps.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'cgps.c') 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) -- cgit v1.2.1