]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix potential use of NULL cache_dir
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Feb 2010 09:06:55 +0000 (10:06 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Feb 2010 09:06:55 +0000 (10:06 +0100)
ccache.c

index 66d5f77c9b2b0abacf0d93d30d1f1275693b6a77..b37bb00382953639d10cc7c219d14716cb5604ba 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1647,7 +1647,7 @@ static void usage(void)
 static void check_cache_dir(void)
 {
        if (!cache_dir) {
-               fatal("Unable to determine home directory");
+               fatal("Unable to determine cache directory");
        }
 }
 
@@ -1783,7 +1783,6 @@ int main(int argc, char *argv[])
        char *p;
 
        current_working_dir = get_cwd();
-
        cache_dir = getenv("CCACHE_DIR");
        if (!cache_dir) {
                const char *home_directory = get_home_directory();
@@ -1792,6 +1791,22 @@ int main(int argc, char *argv[])
                }
        }
 
+       /* check if we are being invoked as "ccache" */
+       if (strlen(argv[0]) >= strlen(MYNAME) &&
+           strcmp(argv[0] + strlen(argv[0]) - strlen(MYNAME), MYNAME) == 0) {
+               if (argc < 2) {
+                       usage();
+                       exit(1);
+               }
+               /* if the first argument isn't an option, then assume we are
+                  being passed a compiler name and options */
+               if (argv[1][0] == '-') {
+                       return ccache_main(argc, argv);
+               }
+       }
+
+       check_cache_dir();
+
        temp_dir = getenv("CCACHE_TEMPDIR");
        if (!temp_dir) {
                x_asprintf(&temp_dir, "%s/tmp", cache_dir);
@@ -1821,21 +1836,6 @@ int main(int argc, char *argv[])
                }
        }
 
-
-       /* check if we are being invoked as "ccache" */
-       if (strlen(argv[0]) >= strlen(MYNAME) &&
-           strcmp(argv[0] + strlen(argv[0]) - strlen(MYNAME), MYNAME) == 0) {
-               if (argc < 2) {
-                       usage();
-                       exit(1);
-               }
-               /* if the first argument isn't an option, then assume we are
-                  being passed a compiler name and options */
-               if (argv[1][0] == '-') {
-                       return ccache_main(argc, argv);
-               }
-       }
-
        /* make sure the cache dir exists */
        if (create_dir(cache_dir) != 0) {
                fprintf(stderr,"ccache: failed to create %s (%s)\n",