changeset 2940:30d30cfe6b47

Handle file == NULL in ungetc().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 22 Sep 2008 06:40:40 +0300
parents 3877a02782bb
children c57d9b5754b3
files src/stdio/stdio.c
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/stdio/stdio.c	Mon Sep 22 06:39:32 2008 +0300
+++ b/src/stdio/stdio.c	Mon Sep 22 06:40:40 2008 +0300
@@ -77,7 +77,7 @@
     gchar *decpath;
 
     if (!path || !mode)
-	return NULL;
+	    return NULL;
 
     decpath = aud_vfs_stdio_urldecode_path(path);
 
@@ -85,8 +85,7 @@
 
     file->handle = fopen(decpath != NULL ? decpath : path, mode);
 
-    if (decpath != NULL)
-        g_free(decpath);
+    g_free(decpath);
 
     if (file->handle == NULL) {
         g_free(file);
@@ -157,11 +156,16 @@
 }
 
 gint
-stdio_aud_vfs_ungetc_impl(gint c, VFSFile *stream)
+stdio_aud_vfs_ungetc_impl(gint c, VFSFile * file)
 {
-  FILE *handle = (FILE *) stream->handle;
-
-  return ungetc( c , handle );
+    FILE *handle;
+    
+    if (file == NULL)
+        return -1;
+	
+	handle = (FILE *) file->handle;
+	
+    return ungetc(c, handle);
 }
 
 gint
@@ -242,7 +246,7 @@
 
     handle = (FILE *) file->handle;
 
-    if (-1 == fstat(fileno(handle), &s))
+    if (fstat(fileno(handle), &s) == -1)
         return -1;
 
     return s.st_size;