PERFORCE change 144026 for review

Gabor Kovesdan gabor at FreeBSD.org
Tue Jun 24 16:16:13 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=144026

Change 144026 by gabor at gabor_server on 2008/06/24 16:15:17

	- Cleanup: use grep_malloc instead of malloc

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/binary.c#10 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#42 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#37 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/grep/binary.c#10 (text+ko) ====

@@ -77,8 +77,7 @@
 	if ((s = mbstowcs(NULL, f->base, 0)) == -1)
 		return (0);
 
-	if ((wbuf = malloc((s + 1) * sizeof(wchar_t))) == NULL)
-		err(2, NULL);
+	wbuf = grep_malloc((s + 1) * sizeof(wchar_t));
 
 	mbstowcs(wbuf, f->base, s);
 

==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#42 (text+ko) ====

@@ -649,8 +649,7 @@
 	else
 		for (c = 0; argc--; ++argv) {
 			if (devbehave == DEV_SKIP) {
-				if (!(finfo = malloc(sizeof(struct stat))))
-					err(2, NULL);
+				finfo = grep_malloc(sizeof(struct stat));
 				if (stat(*argv, finfo) == -1)
 					err(2, NULL);
 				if (S_ISBLK(finfo->st_mode) ||

==== //depot/projects/soc2008/gabor_textproc/grep/util.c#37 (text+ko) ====

@@ -93,8 +93,7 @@
 			if ((devbehave == DEV_SKIP) || (dirbehave == DIR_RECURSE) || (dirbehave == DIR_SKIP)) {
 				struct stat	*finfo;
 
-				if (!(finfo = malloc(sizeof(struct stat))))
-					err(2, NULL);
+				finfo = grep_malloc(sizeof(struct stat));
 				if (stat(p->fts_path, finfo) == -1)
 					err(2, NULL);
 
@@ -233,12 +232,9 @@
 			if ((r == 0) && (color != NULL) && !oflag && !nottext) {
 				char	*tmp, *begin, *matched, *end;
 
-				if ((begin = malloc(strlen(l->dat) - pmatch.rm_so + 1)) == NULL)
-					errx(2, NULL);
-				if ((matched = malloc((pmatch.rm_eo - pmatch.rm_so + 1) * sizeof(char))) == NULL)
-					errx(2, NULL);
-				if ((end = malloc(strlen(l->dat) - pmatch.rm_eo + 1)) == NULL)
-					errx(2, NULL);
+				begin = grep_malloc(strlen(l->dat) - pmatch.rm_so + 1);
+				matched = grep_malloc((pmatch.rm_eo - pmatch.rm_so + 1) * sizeof(char));
+				end = grep_malloc(strlen(l->dat) - pmatch.rm_eo + 1);
 
 				strlcpy(begin, l->dat, pmatch.rm_so + 1);
 				strlcpy(matched, &(l->dat[pmatch.rm_so]), pmatch.rm_eo - pmatch.rm_so + 1);
@@ -256,8 +252,7 @@
 			if (r == 0 && oflag && !nottext) {
 				char	*tmp, *matched;
 
-				if ((matched = malloc((pmatch.rm_eo - pmatch.rm_so + 2) * sizeof(char))) == NULL)
-					errx(2, NULL);
+				matched = grep_malloc((pmatch.rm_eo - pmatch.rm_so + 2) * sizeof(char));
 				strlcpy(matched, &(l->dat[pmatch.rm_so]), pmatch.rm_eo - pmatch.rm_so + 1);
 
 				if (color != NULL)


More information about the p4-projects mailing list