summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/pch.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-06-21 01:48:45 +0000
committerpfg <pfg@FreeBSD.org>2014-06-21 01:48:45 +0000
commit56eadad6c552cf366b03f1759d7794ccc97291f7 (patch)
treef52e00e34423d07617c8faeafa9b81f346ef1901 /usr.bin/patch/pch.c
parenta63ff939c2a4f901e3d48c6fa8fc2198291561ff (diff)
downloadFreeBSD-src-56eadad6c552cf366b03f1759d7794ccc97291f7.zip
FreeBSD-src-56eadad6c552cf366b03f1759d7794ccc97291f7.tar.gz
MFC r267426, r267464:
Avoid zeroing during allocation. This change reverts a change from OpenBSD which made use of calloc, and therefore wasted time initializing arrays that will later be realloc'ed. Consistently use FreeBSD's reallocf(): - Drop some bogus casts to size_t. - The new_p_foo variables are not needed anymore. Also merge the changes from OpenBSD's manpage patch.1 Rev 1.27: "patch was moved from user portability (UP) to base in issue 7 and is no longer optional"
Diffstat (limited to 'usr.bin/patch/pch.c')
-rw-r--r--usr.bin/patch/pch.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index eca12ad..691add1 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -132,11 +132,11 @@ void
set_hunkmax(void)
{
if (p_line == NULL)
- p_line = calloc((size_t) hunkmax, sizeof(char *));
+ p_line = malloc(hunkmax * sizeof(char *));
if (p_len == NULL)
- p_len = calloc((size_t) hunkmax, sizeof(short));
+ p_len = malloc(hunkmax * sizeof(short));
if (p_char == NULL)
- p_char = calloc((size_t) hunkmax, sizeof(char));
+ p_char = malloc(hunkmax * sizeof(char));
}
/*
@@ -145,31 +145,14 @@ set_hunkmax(void)
static void
grow_hunkmax(void)
{
- int new_hunkmax;
- char **new_p_line;
- short *new_p_len;
- char *new_p_char;
-
- new_hunkmax = hunkmax * 2;
+ int new_hunkmax = hunkmax * 2;
if (p_line == NULL || p_len == NULL || p_char == NULL)
fatal("Internal memory allocation error\n");
- new_p_line = realloc(p_line, new_hunkmax * sizeof(char *));
- if (new_p_line == NULL)
- free(p_line);
-
- new_p_len = realloc(p_len, new_hunkmax * sizeof(short));
- if (new_p_len == NULL)
- free(p_len);
-
- new_p_char = realloc(p_char, new_hunkmax * sizeof(char));
- if (new_p_char == NULL)
- free(p_char);
-
- p_char = new_p_char;
- p_len = new_p_len;
- p_line = new_p_line;
+ p_line = reallocf(p_line, new_hunkmax * sizeof(char *));
+ p_len = reallocf(p_len, new_hunkmax * sizeof(short));
+ p_char = reallocf(p_char, new_hunkmax * sizeof(char));
if (p_line != NULL && p_len != NULL && p_char != NULL) {
hunkmax = new_hunkmax;
OpenPOWER on IntegriCloud