]> granicus.if.org Git - nethack/commitdiff
saved game memory initialization (dev only)
authorcohrs <cohrs>
Fri, 23 Feb 2007 03:44:50 +0000 (03:44 +0000)
committercohrs <cohrs>
Fri, 23 Feb 2007 03:44:50 +0000 (03:44 +0000)
Qt windowport crashed on startup because a couple alloc() calls in files.c
were not zero'ing out the memory afterward.  This resulted in uninit'd
memory access if there were no saved games.  This bug is in new dev code.

src/files.c

index 6466b00876c5ab23797c5684e89ffaf56fa6fbe0..5056b708a0abf40fe4dee95d27be2df5608ae7ba 100644 (file)
@@ -1083,6 +1083,7 @@ get_saved_games()
        }
        if (n > 0) {
            result = (char**)alloc((n+1)*sizeof(char*)); /* at most */
+           (void) memset((genericptr_t) result, 0, (n+1)*sizeof(char*));
            if (findfirst((char *)fq_save)) {
            j = n = 0;
            do {
@@ -1110,6 +1111,7 @@ get_saved_games()
                if(!(dir=opendir(fqname("save", SAVEPREFIX, 0))))
                        return 0;
                result = (char**)alloc((n+1)*sizeof(char*)); /* at most */
+               (void) memset((genericptr_t) result, 0, (n+1)*sizeof(char*));
                for (i=0, j=0; i<n; i++) {
                    int uid;
                    char name[64]; /* more than PL_NSIZ */