about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJoe DF <joedf@live.ca>2019-10-15 10:20:44 -0400
committerGitHub <noreply@github.com>2019-10-15 10:20:44 -0400
commita8925f86c953d090b6bf8fb31f8b69a24c77fa7a (patch)
treecfc8f81a16d2bbc86494d9f9afda88047d558949
parent916030dbf8ec72230192b5f9b7d80ce047dfc68d (diff)
parent0fb0a4c0c241cd01a2806492f9bf15d9dbbfba66 (diff)
downloadbase64-a8925f86c953d090b6bf8fb31f8b69a24c77fa7a.tar.gz
Merge pull request #4 from Busyvar/master
fix file closing when error occurs, lint variable type declaration to…
-rw-r--r--base64.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/base64.c b/base64.c
index 1d6bd73..3b97eaa 100644
--- a/base64.c
+++ b/base64.c
@@ -112,13 +112,18 @@ unsigned int b64_decode(const unsigned char* in, unsigned int in_len, unsigned i
 }
 
 unsigned int b64_encodef(char *InFile, char *OutFile) {
-	
-	FILE *pInFile = fopen(InFile,"rb");
-	FILE *pOutFile = fopen(OutFile,"wb");
-	if ( (pInFile==NULL) || (pOutFile==NULL) )
-	return 0;
-	
-	unsigned int i=0, j=0, c=0, s[3];
+	  FILE *pInFile = fopen(InFile,"rb");
+    FILE *pOutFile = fopen(OutFile,"wb");
+    unsigned int i=0;
+    unsigned int j=0;
+    unsigned int c=0;
+    unsigned int s[4];
+    if ((pInFile==NULL) || (pOutFile==NULL) )
+    {
+        if (pInFile!=NULL){fclose(pInFile);}
+        if (pOutFile!=NULL){fclose(pOutFile);}
+        return 0;
+    }
 	
 	while(c!=EOF) {
 		c=fgetc(pInFile);
@@ -155,12 +160,18 @@ unsigned int b64_encodef(char *InFile, char *OutFile) {
 
 unsigned int b64_decodef(char *InFile, char *OutFile) {
 
-	FILE *pInFile = fopen(InFile,"rb");
-	FILE *pOutFile = fopen(OutFile,"wb");
-	if ( (pInFile==NULL) || (pOutFile==NULL) )
-	return 0;
-
-	unsigned int c=0, j=0, k=0, s[4];
+	  FILE *pInFile = fopen(InFile,"rb");
+    FILE *pOutFile = fopen(OutFile,"wb");
+    unsigned int c=0;
+    unsigned int j=0;
+    unsigned int k=0;
+    unsigned int s[4];
+    if ((pInFile==NULL) || (pOutFile==NULL) )
+    {
+        if (pInFile!=NULL){fclose(pInFile);}
+        if (pOutFile!=NULL){fclose(pOutFile);}
+        return 0;
+    }
 	
 	while(c!=EOF) {
 		c=fgetc(pInFile);