projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
[gnulib.git]
/
tests
/
test-getline.c
diff --git
a/tests/test-getline.c
b/tests/test-getline.c
index
bab99b3
..
134e320
100644
(file)
--- a/
tests/test-getline.c
+++ b/
tests/test-getline.c
@@
-1,5
+1,5
@@
/* Test of getline() function.
/* Test of getline() function.
- Copyright (C) 2007-20
09
Free Software Foundation, Inc.
+ Copyright (C) 2007-20
13
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-12,8
+12,7
@@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
/* Written by Eric Blake <ebb9@byu.net>, 2007. */
/* Written by Eric Blake <ebb9@byu.net>, 2007. */
@@
-33,13
+32,13
@@
int
main (void)
{
FILE *f;
main (void)
{
FILE *f;
- char *line
= NULL
;
- size_t len
= 0
;
+ char *line;
+ size_t len;
ssize_t result;
/* Create test file. */
f = fopen ("test-getline.txt", "wb");
ssize_t result;
/* Create test file. */
f = fopen ("test-getline.txt", "wb");
- if (!f || fwrite ("a\n
bc\nd\0f", 1, 8, f) != 8
|| fclose (f) != 0)
+ if (!f || fwrite ("a\n
A\nbc\nd\0f", 1, 10, f) != 10
|| fclose (f) != 0)
{
fputs ("Failed to create sample file.\n", stderr);
remove ("test-getline.txt");
{
fputs ("Failed to create sample file.\n", stderr);
remove ("test-getline.txt");
@@
-54,13
+53,24
@@
main (void)
}
/* Test initial allocation, which must include trailing NUL. */
}
/* Test initial allocation, which must include trailing NUL. */
+ line = NULL;
+ len = 0;
result = getline (&line, &len, f);
ASSERT (result == 2);
ASSERT (strcmp (line, "a\n") == 0);
ASSERT (2 < len);
result = getline (&line, &len, f);
ASSERT (result == 2);
ASSERT (strcmp (line, "a\n") == 0);
ASSERT (2 < len);
+ free (line);
- /* Test growth of buffer, must not leak. */
+ /* Test initial allocation again, with line = NULL and len != 0. */
+ line = NULL;
+ len = (size_t)(~0) / 4;
+ result = getline (&line, &len, f);
+ ASSERT (result == 2);
+ ASSERT (strcmp (line, "A\n") == 0);
+ ASSERT (2 < len);
free (line);
free (line);
+
+ /* Test growth of buffer, must not leak. */
line = malloc (1);
len = 0;
result = getline (&line, &len, f);
line = malloc (1);
len = 0;
result = getline (&line, &len, f);