Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Oct 2009 19:44:41 +0000 (UTC)
From:      David Schultz <das@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r197753 - head/tools/regression/lib/libc/stdio
Message-ID:  <200910041944.n94JifN8083557@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: das
Date: Sun Oct  4 19:44:41 2009
New Revision: 197753
URL: http://svn.freebsd.org/changeset/base/197753

Log:
  Regression tests for r197752 (handling of empty/NULL buffers).

Modified:
  head/tools/regression/lib/libc/stdio/test-getdelim.c

Modified: head/tools/regression/lib/libc/stdio/test-getdelim.c
==============================================================================
--- head/tools/regression/lib/libc/stdio/test-getdelim.c	Sun Oct  4 19:43:36 2009	(r197752)
+++ head/tools/regression/lib/libc/stdio/test-getdelim.c	Sun Oct  4 19:44:41 2009	(r197753)
@@ -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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200910041944.n94JifN8083557>