summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2018-05-24 04:00:37 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-05-24 04:00:37 (GMT)
commit81897b94619b6086c1e5be8af09497ca2eeb102a (patch) (side-by-side diff)
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') (more/less context) (ignore whitespace changes)
-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) \
return 1; \
if (errno == ERANGE || (t = n) != n) \
return 1; \
- xd_store (xd, &n, sizeof (n)); \
+ xd_store (xd, &t, sizeof (t)); \
return 0; \
}
@@ -337,6 +337,23 @@ datum_scan_notag (datum *dat, struct dsegm *ds, struct kvpair *kv)
if (!ds->v.field.type->scan)
abort ();
+ if (kv->type == KV_STRING && ds->v.field.dim > 1)
+ {
+ /* If a char[] value was supplied as a quoted string.
+ convert it it list for further processing */
+ if (ds->v.field.type->size == 1)
+ {
+ struct slist *head = slist_new_l (kv->val.s, 1);
+ struct slist *tail = head;
+ char *s;
+ for (s = kv->val.s + 1; *s; s++)
+ slist_insert (&tail, slist_new_l (s, 1));
+ free (kv->val.s);
+ kv->val.l = head;
+ kv->type = KV_LIST;
+ }
+ }
+
switch (kv->type)
{
case KV_STRING:
@@ -358,7 +375,11 @@ datum_scan_notag (datum *dat, struct dsegm *ds, struct kvpair *kv)
break;
}
}
- /* FIXME: Warn if (s) -> "extra data" */
+ if (s)
+ {
+ lerror (&kv->loc, "surplus initializers ignored");
+ err = 1;
+ }
}
break;

Return to:

Send suggestions and report system problems to the System administrator.