File: check-return-value.patch

package info (click to toggle)
adun.app 0.81-14
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 16,672 kB
  • sloc: objc: 70,914; ansic: 6,662; yacc: 394; python: 75; cpp: 36; makefile: 35; xml: 15; awk: 3
file content (92 lines) | stat: -rw-r--r-- 3,073 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Description: Check the return value of `freopen' and `fread'.
Author: Yavor Doganov <yavor@gnu.org>
Forwarded: no
Last-Update: 2018-01-08
---

--- adun.app.orig/Kernel/AdunKernel/CoreAdditions/AdunIOManager.m
+++ adun.app/Kernel/AdunKernel/CoreAdditions/AdunIOManager.m
@@ -515,8 +515,10 @@
 	
 	GSPrintf(stdout, @"Error file is %@\n", errorFile);
 	fflush(stderr);
-	freopen([errorFile cString], "w", stderr);
-	freopen([logFile cString], "w", stdout);
+	if (freopen([errorFile cString], "w", stderr) == NULL)
+	  NSLog(@"%@: freopen failed", errorFile);
+	if (freopen([logFile cString], "w", stdout) == NULL)
+	  NSLog(@"%@: freopen failed", logFile);
 	
 	return YES;	
 }
@@ -596,8 +598,10 @@
 	} 
 
 	fflush(stderr);
-	freopen([errorFile cString], "a", stderr);
-	freopen([logFile cString], "a", stdout);
+	if (freopen([errorFile cString], "a", stderr) == NULL)
+	  NSLog(@"%@: freopen failed", errorFile);
+	if (freopen([logFile cString], "a", stdout) == NULL)
+	  NSLog(@"%@: freopen failed", logFile);
 
 	GSPrintf(stdout, @"%@%@", divider, divider);
 	GSPrintf(stdout, @"%@ - Continuing Simulation\n", AdTimeStamp());
@@ -861,8 +865,8 @@
 				 * Work around by reading in old file and writing to the new one.
 				 */
 				contents = [NSString stringWithContentsOfFile: logFile];
-				freopen([newLocation cString], "w", stdout);
-				GSPrintf(stdout, @"%@\n", contents);
+				if (freopen([newLocation cString], "w", stdout))
+				  GSPrintf(stdout, @"%@\n", contents);
 				[[NSFileManager defaultManager] removeFileAtPath: logFile
 					handler: nil];
 				[logFile release];	
@@ -888,8 +892,8 @@
 				 * Work around by reading in old file and writing to the new one.
 				 */
 				contents = [NSString stringWithContentsOfFile: errorFile];
-				freopen([newLocation cString], "w", stderr);
-				GSPrintf(stderr, @"%@\n", contents);
+				if(freopen([newLocation cString], "w", stderr))
+				  GSPrintf(stderr, @"%@\n", contents);
 				[[NSFileManager defaultManager]
 					removeFileAtPath: errorFile
 					handler: nil];
--- adun.app.orig/MolTalk/MTFileStream.m
+++ adun.app/MolTalk/MTFileStream.m
@@ -321,7 +321,8 @@
 	FILE *t_file = fopen([filepath cString],"r");
 	if (t_file)
 	{
-		fread(buffer,1,2,t_file);
+		if (fread(buffer,1,2,t_file) < 2)
+		        return NO;
 		//printf("file compressed? %03d %03d\n",buffer[0],buffer[1]);
 		fclose(t_file);
 		if (buffer[0]==31 && buffer[1]==157)
--- adun.app.orig/UL/AdunServer/AdServer.m
+++ adun.app/UL/AdunServer/AdServer.m
@@ -158,7 +158,8 @@
 		}
 	} 
 
-	freopen([logFile cString], "w", stderr);
+	if (freopen([logFile cString], "w", stderr) == NULL)
+	  NSLog(@"%@: freopen failed", logFile);
 }
 
 - (void) _connectToDefaultDatabase
--- adun.app.orig/UL/ViewController.m
+++ adun.app/UL/ViewController.m
@@ -184,7 +184,8 @@
 			NSWarnLog(@"Switching to registered default %@", logFile);
 		} 
 
-		freopen([logFile cString], "w", stderr);
+		if (freopen([logFile cString], "w", stderr) == NULL)
+		  NSLog(@"%@: freopen failed", logFile);
 
 		//the methods to be forwarded to the 
 		//active delegate.