summaryrefslogtreecommitdiffabout
path: root/tests
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-08 08:28:53 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-07-08 11:12:34 (GMT)
commit4aef6b36f862e46723403bc6422ac47058a5ef19 (patch) (side-by-side diff)
treefa7afe6ed8f1abf080fa764bda1bbc81e07f407b /tests
parent260102cf7f75db3c87d04a06eb8054853cacce97 (diff)
downloadgdbm-4aef6b36f862e46723403bc6422ac47058a5ef19.tar.gz
gdbm-4aef6b36f862e46723403bc6422ac47058a5ef19.tar.bz2
Fix error handling in gdbm_fetch, gdbm_firstkey, and gdbm_nextkey.
* src/gdbmfetch.c: Hanlde out of memory error. * src/findkey.c: Set gdbm_errno to GDBM_ITEM_NOT_FOUND if nothing was found. * src/gdbmdelete.c: Don't set gdbm_errno after _gdbm_findkey returns -1. It's been done already. * src/gdbmexp.c (gdbm_export_to_file): Return -1 if gdbm_fetch fails. * src/gdbmseq.c (get_next_key): Set gdbm_errno to GDBM_ITEM_NOT_FOUND if there's no next key. Don't call _gdbm_fatal on out of memory condition. (gdbm_nextkey): Set gdbm_errno to GDBM_ITEM_NOT_FOUND if there's no next key. * src/gdbmtool.c (fetch_handler) (firstkey_handler,nextkey_handler): Check gdbm_errno. * src/gdbmstore.c: Handle error return from _gdbm_findkey. * tests/gtdump.c: Likewise. * tests/gtfetch.c: Likewise. * doc/gdbm.texi: Document changes. * doc/gdbm.3: Likewise. * configure.ac: Version 1.12.90 * NEWS: Update. * .gitignore: Update.
Diffstat (limited to 'tests') (more/less context) (ignore whitespace changes)
-rw-r--r--tests/gtdump.c13
-rw-r--r--tests/gtfetch.c16
2 files changed, 22 insertions, 7 deletions
diff --git a/tests/gtdump.c b/tests/gtdump.c
index 927a47c..9e151d9 100644
--- a/tests/gtdump.c
+++ b/tests/gtdump.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM test suite.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2016 Free Software Foundation, Inc.
GDBM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -83,7 +83,7 @@ main (int argc, char **argv)
while (key.dptr)
{
size_t i;
- datum nextkey = gdbm_nextkey (dbf, key);
+ datum nextkey;
for (i = 0; i < key.dsize && key.dptr[i]; i++)
{
@@ -103,11 +103,18 @@ main (int argc, char **argv)
free (data.dptr);
fputc ('\n', stdout);
-
+
+ nextkey = gdbm_nextkey (dbf, key);
free (key.dptr);
key = nextkey;
}
+ if (gdbm_errno != GDBM_ITEM_NOT_FOUND)
+ {
+ fprintf (stderr, "unexpected error: %s\n", gdbm_strerror (gdbm_errno));
+ exit (1);
+ }
+
gdbm_close (dbf);
exit (0);
}
diff --git a/tests/gtfetch.c b/tests/gtfetch.c
index 0c254b7..63598ee 100644
--- a/tests/gtfetch.c
+++ b/tests/gtfetch.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM test suite.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2016 Free Software Foundation, Inc.
GDBM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -105,9 +105,17 @@ main (int argc, char **argv)
if (data.dptr == NULL)
{
rc = 2;
- fprintf (stderr, "%s: ", progname);
- print_key (stderr, key, delim);
- fprintf (stderr, ": not found\n");
+ if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+ {
+ fprintf (stderr, "%s: ", progname);
+ print_key (stderr, key, delim);
+ fprintf (stderr, ": not found\n");
+ }
+ else
+ {
+ fprintf (stderr, "%s: error: %s\n", progname,
+ gdbm_strerror (gdbm_errno));
+ }
continue;
}
if (delim)

Return to:

Send suggestions and report system problems to the System administrator.