nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] patch for minor errors in new code


From: David Lawrence Ramsey
Subject: [Nano-devel] patch for minor errors in new code
Date: Fri, 15 Feb 2002 19:41:27 -0800 (PST)

Thanks for merging my last patch.  However, I've found
and fixed some minor errors in (mostly) the code it
introduced:

There were two minor oversights in
check_writable_directory(): the "writable" variable wasn't
really needed, as the function would return NULL if the
directory wasn't readable, and the value of full_path,
which was dynamically allocated, was never free()d if an
error occurred and the function had to return NULL.  Both
are fixed in the attached patch.  Also, the patch contains
an addition to the comments at the beginning of
safe_tempnam(), explaining a detail of the implementation
(the lack of reference to TMP_MAX) more clearly.  Finally,
it also has the rcfile fix I mentioned in my last email.

Sorry I didn't catch all this sooner.


_____________________________________________________________
Sluggy.Net: The Sluggy Freelance Community!
diff -urN nano-1.1.6-cvs/files.c nano-1.1.6-cvs-fixed/files.c
--- nano-1.1.6-cvs/files.c      Fri Feb 15 14:17:02 2002
+++ nano-1.1.6-cvs-fixed/files.c        Fri Feb 15 22:30:50 2002
@@ -1024,36 +1024,35 @@
 
 #ifndef DISABLE_SPELLER
 /*
- * This function accepts a path and a pointer to an integer, and returns
- * the full path (via get_full_path()).  It also sets the integer
- * pointer's referenced value to 1 if the full path is writable, and 0
- * otherwise.  On error, it returns NULL, and sets the pointer's
- * referenced value to 0.
+ * This function accepts a path and returns the full path (via
+ * get_full_path()).  On error, if the path doesn't reference a
+ * directory, or if the directory isn't writable, it returns NULL.
  */
-char *check_writable_directory(const char *path, int *writable) {
+char *check_writable_directory(const char *path) {
 
     char *full_path = get_full_path(path);
+    int writable;
     struct stat fileinfo;
 
-    /* if get_full_path() failed, set *writable to 0 and return NULL */
-    if (!full_path) {
-       *writable = 0;
+    /* if get_full_path() failed, return NULL */
+    if (!full_path)
        return NULL;
-    }
-    else {
-       /* otherwise, stat() the full path to see if it's writable by the
-          user; set *writable to 1 if it is, or 0 if it isn't */
-       stat(path, &fileinfo);
-       if (fileinfo.st_mode & S_IWUSR)
-           *writable = 1;
-       else
-           *writable = 0;
-    }
+
+    /* otherwise, stat() the full path to see if it's writable by the
+       user; set writable to 1 if it is, or 0 if it isn't */
+    stat(path, &fileinfo);
+    if (fileinfo.st_mode & S_IWUSR)
+       writable = 1;
+    else
+       writable = 0;
 
     /* if the full path doesn't end in a slash (meaning get_full_path()
-       found that it isn't a directory) or isn't writable, return NULL */
-    if (full_path[strlen(full_path) - 1] != '/' || *writable == 0)
+       found that it isn't a directory) or isn't writable, free full_path
+       and return NULL */
+    if (full_path[strlen(full_path) - 1] != '/' || writable == 0) {
+       free(full_path);
        return NULL;
+    }
 
     /* otherwise, return the full path */
     return full_path;
@@ -1064,12 +1063,18 @@
  * way that tempnam() does, determines the location for its temporary
  * file the same way that tempnam() does, safely creates the temporary
  * file there via mkstemp(), and returns the name of the temporary file
- * the same way that tempnam() does.
+ * the same way that tempnam() does.  It does not reference the value of
+ * TMP_MAX because the total number of random filenames that it can
+ * generate using one prefix is equal to 256**6, which is a sufficiently
+ * large number to handle most cases.  Since the behavior after tempnam()
+ * generates TMP_MAX random filenames is implementation-defined, my
+ * implementation is to go on generating random filenames regardless of
+ * it.
  */
 char *safe_tempnam(const char *dirname, const char *filename_prefix) {
 
     char *buf, *tempdir = NULL, *full_tempdir = NULL;
-    int writable = 0, filedesc;
+    int filedesc;
 
     /* if $TMPDIR is set and non-empty, set tempdir to it, run it through
        get_full_path(), and save the result in full_tempdir; otherwise,
@@ -1080,7 +1085,7 @@
           get_full_path(), and save the result in full_tempdir */
        tempdir = charalloc(strlen(getenv("TMPDIR")) + 1);
        sprintf(tempdir, "%s", getenv("TMPDIR"));
-       full_tempdir = check_writable_directory(tempdir, &writable);
+       full_tempdir = check_writable_directory(tempdir);
 
        /* we don't need the value of tempdir anymore */
        free(tempdir);
@@ -1094,7 +1099,7 @@
        if (dirname) {
            tempdir = charalloc(strlen(dirname) + 1);
            strcpy(tempdir, dirname);
-           full_tempdir = check_writable_directory(tempdir, &writable);
+           full_tempdir = check_writable_directory(tempdir);
 
            /* we don't need the value of tempdir anymore */
            free(tempdir);
@@ -1106,7 +1111,7 @@
     if (!full_tempdir) {
        tempdir = charalloc(strlen(P_tmpdir) + 1);
        strcpy(tempdir, P_tmpdir);
-       full_tempdir = check_writable_directory(tempdir, &writable);
+       full_tempdir = check_writable_directory(tempdir);
 
        /* we don't need the value of tempdir anymore */
        free(tempdir);
diff -urN nano-1.1.6-cvs/proto.h nano-1.1.6-cvs-fixed/proto.h
--- nano-1.1.6-cvs/proto.h      Fri Feb 15 14:17:02 2002
+++ nano-1.1.6-cvs-fixed/proto.h        Fri Feb 15 22:22:35 2002
@@ -224,7 +224,7 @@
 #endif
 
 #ifndef DISABLE_SPELLER
-char *check_writable_directory(const char *path, int *writable);
+char *check_writable_directory(const char *path);
 char *safe_tempnam(const char *dirname, const char *filename_prefix);
 #endif
 
diff -urN nano-1.1.6-cvs/rcfile.c nano-1.1.6-cvs-fixed/rcfile.c
--- nano-1.1.6-cvs/rcfile.c     Fri Feb 15 14:17:02 2002
+++ nano-1.1.6-cvs-fixed/rcfile.c       Fri Feb 15 22:31:05 2002
@@ -40,7 +40,7 @@
 #define _(string) (string)
 #endif
 
-#define NUM_RCOPTS 21
+#define NUM_RCOPTS 20
 
 /* Static stuff for the nanorc file */
 rcoption rcopts[NUM_RCOPTS] = {
@@ -63,7 +63,6 @@
     {"multibuffer", MULTIBUFFER},
     {"smooth", SMOOTHSCROLL},
     {"keypad", ALT_KEYPAD},
-    {"relative", RELATIVECHARS},
     {"noconvert", NO_CONVERT}
 };
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]