fix signed range problems with hex conversions
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index d8f9242ea8fe2ee92884623939a85b6587a3ad9d..487168be40d6cf68e3b3f0fbd713cd36ced8f1ed 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -137,13 +137,11 @@ static const char *external_diff(void)
        return external_diff_cmd;
 }
 
-#define TEMPFILE_PATH_LEN              50
-
 static struct diff_tempfile {
        const char *name; /* filename external diff should read from */
        char hex[41];
        char mode[10];
-       char tmp_path[TEMPFILE_PATH_LEN];
+       char tmp_path[PATH_MAX];
 } diff_temp[2];
 
 static int count_lines(const char *data, int size)
@@ -1260,7 +1258,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
 }
 
 /*
- * Given a name and sha1 pair, if the dircache tells us the file in
+ * Given a name and sha1 pair, if the index tells us the file in
  * the work tree has that object contents, return true, so that
  * prepare_temp_file() does not have to inflate and extract.
  */
@@ -1468,14 +1466,15 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
                enum object_type type;
                struct sha1_size_cache *e;
 
+               if (size_only && use_size_cache &&
+                   (e = locate_size_cache(s->sha1, 1, 0)) != NULL) {
+                       s->size = e->size;
+                       return 0;
+               }
+
                if (size_only) {
-                       e = locate_size_cache(s->sha1, 1, 0);
-                       if (e) {
-                               s->size = e->size;
-                               return 0;
-                       }
                        type = sha1_object_info(s->sha1, &s->size);
-                       if (type < 0)
+                       if (use_size_cache && 0 < type)
                                locate_size_cache(s->sha1, 0, s->size);
                }
                else {
@@ -1506,7 +1505,7 @@ static void prep_temp_blob(struct diff_tempfile *temp,
 {
        int fd;
 
-       fd = git_mkstemp(temp->tmp_path, TEMPFILE_PATH_LEN, ".diff_XXXXXX");
+       fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
        if (fd < 0)
                die("unable to create temp-file");
        if (write_in_full(fd, blob, size) != size)