summaryrefslogtreecommitdiff
path: root/gpsd_json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-10-13 22:28:47 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-10-13 22:28:47 -0400
commit7fe72f79f289166b3b23947a198a3f511bf5bf52 (patch)
tree621c9823f18cc86825d23a11d6b6299e35041508 /gpsd_json.c
parent5ae819b8e4b9df0da24953355d6d05b9001a82a9 (diff)
downloadgpsd-7fe72f79f289166b3b23947a198a3f511bf5bf52.tar.gz
Make all hex-dumping truly thread-safe.
Diffstat (limited to 'gpsd_json.c')
-rw-r--r--gpsd_json.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/gpsd_json.c b/gpsd_json.c
index e91dad6b..dbebcc5c 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -1369,6 +1369,7 @@ void json_aivdm_dump(const struct ais_t *ais,
char buf2[JSON_VAL_MAX * 2 + 1];
char buf3[JSON_VAL_MAX * 2 + 1];
char buf4[JSON_VAL_MAX * 2 + 1];
+ char scratchbuf[MAX_PACKET_LENGTH*2+1];
bool structured;
int i;
@@ -2205,8 +2206,9 @@ void json_aivdm_dump(const struct ais_t *ais,
"\"data\":\"%zd:%s\"}\r\n",
ais->type6.bitcount,
json_stringify(buf1, sizeof(buf1),
- gpsd_hexdump((char *)ais->type6.bitdata,
- (ais->type6.bitcount + 7) / 8)));
+ gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
+ (char *)ais->type6.bitdata,
+ (ais->type6.bitcount + 7) / 8)));
break;
case 7: /* Binary Acknowledge */
case 13: /* Safety Related Acknowledge */
@@ -2900,7 +2902,8 @@ void json_aivdm_dump(const struct ais_t *ais,
"\"data\":\"%zd:%s\"}\r\n",
ais->type8.bitcount,
json_stringify(buf1, sizeof(buf1),
- gpsd_hexdump((char *)ais->type8.bitdata,
+ gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
+ (char *)ais->type8.bitdata,
(ais->type8.bitcount + 7) / 8)));
break;
case 9: /* Standard SAR Aircraft Position Report */
@@ -3012,7 +3015,8 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type17.lon / AIS_GNSS_LATLON_DIV,
ais->type17.lat / AIS_GNSS_LATLON_DIV,
ais->type17.bitcount,
- gpsd_hexdump((char *)ais->type17.bitdata,
+ gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
+ (char *)ais->type17.bitdata,
(ais->type17.bitcount + 7) / 8));
} else {
(void)snprintf(buf + strlen(buf), buflen - strlen(buf),
@@ -3020,7 +3024,8 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type17.lon,
ais->type17.lat,
ais->type17.bitcount,
- gpsd_hexdump((char *)ais->type17.bitdata,
+ gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
+ (char *)ais->type17.bitdata,
(ais->type17.bitcount + 7) / 8));
}
break;
@@ -3346,7 +3351,8 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type25.dest_mmsi,
ais->type25.app_id,
ais->type25.bitcount,
- gpsd_hexdump((char *)ais->type25.bitdata,
+ gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
+ (char *)ais->type25.bitdata,
(ais->type25.bitcount + 7) / 8));
break;
case 26: /* Binary Message, Multiple Slot */
@@ -3358,7 +3364,8 @@ void json_aivdm_dump(const struct ais_t *ais,
ais->type26.dest_mmsi,
ais->type26.app_id,
ais->type26.bitcount,
- gpsd_hexdump((char *)ais->type26.bitdata,
+ gpsd_hexdump(scratchbuf, sizeof(scratchbuf),
+ (char *)ais->type26.bitdata,
(ais->type26.bitcount + 7) / 8),
ais->type26.radio);
break;