File: cppcheck-warning-fixes

package info (click to toggle)
rman 3.2-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,296 kB
  • sloc: ansic: 3,607; perl: 451; sh: 334; makefile: 77
file content (42 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Description: the patch fixes cppcheck warnings http://osdir.com/ml/general/2011-01/msg09770.html
Author: Anton Gladky <gladky.anton@gmail.com>

--- a/rman.c
+++ b/rman.c
@@ -3978,7 +3978,7 @@
 			fgets(buffer, sizeof buffer, proc); /* label line */
 			fgets(buffer, sizeof buffer, proc); /* length line */
 			sscanf(buffer, "%lu %lu", &compr, &uncomp);
-			fclose(proc);
+			pclose(proc);
 			/* Boy, don't you wish stat would do that? */
 			sobuf = malloc(uncomp + 1);
 			if (sobuf!=NULL) {
@@ -3992,7 +3992,7 @@
 						source_subfile(sobuf);
 						err = 0;
 					}
-					fclose(proc);
+					pclose(proc);
 				}
 				free(sobuf);
 			}
@@ -4615,10 +4615,16 @@
 filesuck(FILE *in) {
   const int inc=1024*100;	/* what's 100K these days? */
   int len=0,cnt;
-  char *file = malloc(1);  /*NULL -- relloc on NULL not reducing to malloc on some machines? */
+  char *file;
 
   do {
-    file = realloc(file, len+inc+1);	/* what's the ANSI way to find the file size? */
+    char *tmp = realloc(file, len + inc + 1);
+    if(!tmp) {
+     free(file);
+     fprintf(stderr, "Out of memory\n");
+     exit(EXIT_FAILURE);
+    }
+    file = tmp;
     cnt = fread(&file[len], 1, inc, in);
     len+=cnt;
   } while (cnt==inc);