summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-10-04 19:44:41 +0000
committerdas <das@FreeBSD.org>2009-10-04 19:44:41 +0000
commit1651d7d4af797602a83840e4c7d6cb7e21c50699 (patch)
tree411d3cb88512e87dc681136cb2242a1004a77161 /tools
parentbeb0df0cdc08eb2f41c970801e05caae7e59c786 (diff)
downloadFreeBSD-src-1651d7d4af797602a83840e4c7d6cb7e21c50699.zip
FreeBSD-src-1651d7d4af797602a83840e4c7d6cb7e21c50699.tar.gz
Regression tests for r197752 (handling of empty/NULL buffers).
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/lib/libc/stdio/test-getdelim.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/regression/lib/libc/stdio/test-getdelim.c b/tools/regression/lib/libc/stdio/test-getdelim.c
index 1102c20..c68c21e 100644
--- a/tools/regression/lib/libc/stdio/test-getdelim.c
+++ b/tools/regression/lib/libc/stdio/test-getdelim.c
@@ -80,7 +80,7 @@ main(int argc, char *argv[])
srandom(0);
- printf("1..5\n");
+ printf("1..6\n");
/*
* Test multiple times with different buffer sizes
@@ -103,6 +103,7 @@ main(int argc, char *argv[])
assert(getline(&line, &linecap, fp) == -1);
assert(line[0] == '\0');
free(line);
+ line = NULL;
assert(feof(fp));
assert(!ferror(fp));
fclose(fp);
@@ -164,5 +165,23 @@ main(int argc, char *argv[])
fclose(fp);
printf("ok 5 - nul\n");
+ /* Make sure NULL *linep and zero *linecapp are handled. */
+ fp = mkfilebuf();
+ free(line);
+ line = NULL;
+ linecap = 42;
+ assert(getline(&line, &linecap, fp) == sizeof(apothegm) - 1);
+ assert(memcmp(line, apothegm, sizeof(apothegm)) == 0);
+ fp = mkfilebuf();
+ free(line);
+ line = malloc(100);
+ linecap = 0;
+ assert(getline(&line, &linecap, fp) == sizeof(apothegm) - 1);
+ assert(memcmp(line, apothegm, sizeof(apothegm)) == 0);
+ free(line);
+ assert(!ferror(fp));
+ fclose(fp);
+ printf("ok 6 - empty/NULL initial buffer\n");
+
exit(0);
}
OpenPOWER on IntegriCloud