pch.c (267426) | pch.c (267464) |
---|---|
1 2/*- 3 * Copyright 1986, Larry Wall 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following condition is met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this condition and the following disclaimer. --- 11 unchanged lines hidden (view full) --- 20 * SUCH DAMAGE. 21 * 22 * patch - a program to apply diffs to original files 23 * 24 * -C option added in 1998, original code by Marc Espie, based on FreeBSD 25 * behaviour 26 * 27 * $OpenBSD: pch.c,v 1.39 2012/04/11 08:07:13 ajacoutot Exp $ | 1 2/*- 3 * Copyright 1986, Larry Wall 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following condition is met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this condition and the following disclaimer. --- 11 unchanged lines hidden (view full) --- 20 * SUCH DAMAGE. 21 * 22 * patch - a program to apply diffs to original files 23 * 24 * -C option added in 1998, original code by Marc Espie, based on FreeBSD 25 * behaviour 26 * 27 * $OpenBSD: pch.c,v 1.39 2012/04/11 08:07:13 ajacoutot Exp $ |
28 * $FreeBSD: head/usr.bin/patch/pch.c 267426 2014-06-12 19:01:57Z pfg $ | 28 * $FreeBSD: head/usr.bin/patch/pch.c 267464 2014-06-14 01:58:33Z pfg $ |
29 */ 30 31#include <sys/types.h> 32#include <sys/stat.h> 33 34#include <ctype.h> 35#include <libgen.h> 36#include <limits.h> --- 90 unchanged lines hidden (view full) --- 127 128/* 129 * Make sure our dynamically realloced tables are malloced to begin with. 130 */ 131void 132set_hunkmax(void) 133{ 134 if (p_line == NULL) | 29 */ 30 31#include <sys/types.h> 32#include <sys/stat.h> 33 34#include <ctype.h> 35#include <libgen.h> 36#include <limits.h> --- 90 unchanged lines hidden (view full) --- 127 128/* 129 * Make sure our dynamically realloced tables are malloced to begin with. 130 */ 131void 132set_hunkmax(void) 133{ 134 if (p_line == NULL) |
135 p_line = malloc((size_t) hunkmax * sizeof(char *)); | 135 p_line = malloc(hunkmax * sizeof(char *)); |
136 if (p_len == NULL) | 136 if (p_len == NULL) |
137 p_len = malloc((size_t) hunkmax * sizeof(short)); | 137 p_len = malloc(hunkmax * sizeof(short)); |
138 if (p_char == NULL) | 138 if (p_char == NULL) |
139 p_char = malloc((size_t) hunkmax * sizeof(char)); | 139 p_char = malloc(hunkmax * sizeof(char)); |
140} 141 142/* 143 * Enlarge the arrays containing the current hunk of patch. 144 */ 145static void 146grow_hunkmax(void) 147{ | 140} 141 142/* 143 * Enlarge the arrays containing the current hunk of patch. 144 */ 145static void 146grow_hunkmax(void) 147{ |
148 int new_hunkmax; 149 char **new_p_line; 150 short *new_p_len; 151 char *new_p_char; | 148 int new_hunkmax = hunkmax * 2; |
152 | 149 |
153 new_hunkmax = hunkmax * 2; 154 | |
155 if (p_line == NULL || p_len == NULL || p_char == NULL) 156 fatal("Internal memory allocation error\n"); 157 | 150 if (p_line == NULL || p_len == NULL || p_char == NULL) 151 fatal("Internal memory allocation error\n"); 152 |
158 new_p_line = reallocf(p_line, new_hunkmax * sizeof(char *)); 159 new_p_len = reallocf(p_len, new_hunkmax * sizeof(short)); 160 new_p_char = reallocf(p_char, new_hunkmax * sizeof(char)); | 153 p_line = reallocf(p_line, new_hunkmax * sizeof(char *)); 154 p_len = reallocf(p_len, new_hunkmax * sizeof(short)); 155 p_char = reallocf(p_char, new_hunkmax * sizeof(char)); |
161 | 156 |
162 p_char = new_p_char; 163 p_len = new_p_len; 164 p_line = new_p_line; 165 | |
166 if (p_line != NULL && p_len != NULL && p_char != NULL) { 167 hunkmax = new_hunkmax; 168 return; 169 } 170 171 if (!using_plan_a) 172 fatal("out of memory\n"); 173 out_of_mem = true; /* whatever is null will be allocated again */ --- 1415 unchanged lines hidden --- | 157 if (p_line != NULL && p_len != NULL && p_char != NULL) { 158 hunkmax = new_hunkmax; 159 return; 160 } 161 162 if (!using_plan_a) 163 fatal("out of memory\n"); 164 out_of_mem = true; /* whatever is null will be allocated again */ --- 1415 unchanged lines hidden --- |