aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-05-24 07:00:37 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-05-24 07:00:37 +0300
commit81897b94619b6086c1e5be8af09497ca2eeb102a (patch)
treebec0886b679f53cf7c055c2c18b5b33483bc64c6 /src
parent7edbff3372dfd387e4f6da45f43ba8ada6dfbe43 (diff)
downloadgdbm-81897b94619b6086c1e5be8af09497ca2eeb102a.tar.gz
gdbm-81897b94619b6086c1e5be8af09497ca2eeb102a.tar.bz2
gdbmtool: fix data conversion when storing structured content.
* src/datconv.c (DEFNSCAN): Use proper target type to store in datum. (datum_scan_notag): Accept C-like initialization of array of characters by a quoted string.
Diffstat (limited to 'src')
-rw-r--r--src/datconv.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/datconv.c b/src/datconv.c
index cbbe1b0..d29ec84 100644
--- a/src/datconv.c
+++ b/src/datconv.c
@@ -98,7 +98,7 @@ name (struct xdatum *xd, char *str) \
98 return 1; \ 98 return 1; \
99 if (errno == ERANGE || (t = n) != n) \ 99 if (errno == ERANGE || (t = n) != n) \
100 return 1; \ 100 return 1; \
101 xd_store (xd, &n, sizeof (n)); \ 101 xd_store (xd, &t, sizeof (t)); \
102 return 0; \ 102 return 0; \
103} 103}
104 104
@@ -337,6 +337,23 @@ datum_scan_notag (datum *dat, struct dsegm *ds, struct kvpair *kv)
337 if (!ds->v.field.type->scan) 337 if (!ds->v.field.type->scan)
338 abort (); 338 abort ();
339 339
340 if (kv->type == KV_STRING && ds->v.field.dim > 1)
341 {
342 /* If a char[] value was supplied as a quoted string.
343 convert it it list for further processing */
344 if (ds->v.field.type->size == 1)
345 {
346 struct slist *head = slist_new_l (kv->val.s, 1);
347 struct slist *tail = head;
348 char *s;
349 for (s = kv->val.s + 1; *s; s++)
350 slist_insert (&tail, slist_new_l (s, 1));
351 free (kv->val.s);
352 kv->val.l = head;
353 kv->type = KV_LIST;
354 }
355 }
356
340 switch (kv->type) 357 switch (kv->type)
341 { 358 {
342 case KV_STRING: 359 case KV_STRING:
@@ -358,7 +375,11 @@ datum_scan_notag (datum *dat, struct dsegm *ds, struct kvpair *kv)
358 break; 375 break;
359 } 376 }
360 } 377 }
361 /* FIXME: Warn if (s) -> "extra data" */ 378 if (s)
379 {
380 lerror (&kv->loc, "surplus initializers ignored");
381 err = 1;
382 }
362 } 383 }
363 break; 384 break;
364 385

Return to:

Send suggestions and report system problems to the System administrator.