Modify README. Remove redundant assignment from overwrite.c.

Add additional error handling to overwrite.c.
This commit is contained in:
Mid Favila 2022-09-13 18:12:37 -04:00
parent cd3f05e0b8
commit 9d80a006d5
2 changed files with 33 additions and 32 deletions

1
README
View File

@ -13,4 +13,5 @@
line, so long as it doesn't cause a word-split.
-overwrite: Reads stdin and writes it to the provided file. [done]
-shuf: Accepts an arbitrary number of arguments; returns one at random.
-rand: Shell interface to the C rand() function.

View File

@ -14,7 +14,6 @@ int main(int argc, char **argv)
char *buf;
FILE *fp;
strlen = 0;
buflen = 0;
/* arbitrary */
buflen = 4096;
@ -29,9 +28,10 @@ int main(int argc, char **argv)
for(;((c = getchar()) != EOF);)
{
if(strlen == buflen)
if(strlen == buflen && !(buf = realloc(buf, (buflen*=2))))
{
buf = realloc(buf, (buflen*=2));
/* realloc failed */
throw(MALLOC_FAIL, NULL);
}
buf[strlen++] = c;
}