fix for crash with new buildinfo, when gmtime() returns NULL
authorCampbell Barton <ideasman42@gmail.com>
Sun, 17 Nov 2013 15:39:26 +0000 (02:39 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 17 Nov 2013 15:41:28 +0000 (02:41 +1100)
source/blender/blenloader/intern/readfile.c
source/creator/creator.c

index e2876317e383bf3ceb8c18e8f6f9004256ea6ab0..01a71cfd63d38d86381e57d4db0dcd7cd3354560 100644 (file)
@@ -7932,7 +7932,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                char build_commit_datetime[32];
                time_t temp_time = main->build_commit_timestamp;
                struct tm *tm = gmtime(&temp_time);
-               strftime(build_commit_datetime, sizeof(build_commit_datetime), "%Y-%m-%d %H:%M", tm);
+               if (LIKELY(tm)) {
+                       strftime(build_commit_datetime, sizeof(build_commit_datetime), "%Y-%m-%d %H:%M", tm);
+               }
+               else {
+                       BLI_strncpy(build_commit_datetime, "date-unknown", sizeof(build_commit_datetime));
+               }
 
                printf("read file %s\n  Version %d sub %d date %s hash %s\n",
                       fd->relabase, main->versionfile, main->subversionfile,
index 508847af5e3d662241aaa33e4a63c5753359a136..adedab80338fd56b2baec406c75bc7d60393ef58 100644 (file)
@@ -1516,8 +1516,15 @@ int main(int argc, const char **argv)
        {
                time_t temp_time = build_commit_timestamp;
                struct tm *tm = gmtime(&temp_time);
-               strftime(build_commit_date, sizeof(build_commit_date), "%Y-%m-%d", tm);
-               strftime(build_commit_time, sizeof(build_commit_time), "%H:%M", tm);
+               if (LIKELY(tm)) {
+                       strftime(build_commit_date, sizeof(build_commit_date), "%Y-%m-%d", tm);
+                       strftime(build_commit_time, sizeof(build_commit_time), "%H:%M", tm);
+               }
+               else {
+                       const char *unknown = "date-unknown";
+                       BLI_strncpy(build_commit_date, unknown, sizeof(build_commit_date));
+                       BLI_strncpy(build_commit_time, unknown, sizeof(build_commit_time));
+               }
        }
 #endif