d261f558e0a577ee269fe55215505668cdcb6f2a markd Wed Jul 7 07:09:11 2021 -0700 Address several cases of possible uninitialized variables detected by -O3. None of these appear to be actually bugs due to the flow of the code diff --git src/lib/fof.c src/lib/fof.c index feb3295..b501e9c 100644 --- src/lib/fof.c +++ src/lib/fof.c @@ -1,26 +1,28 @@ /* fofFa - create a fof index for a list of FA files. * * This file is copyright 2002 Jim Kent, but license is hereby * granted for all use - public, private or commercial. */ #include "common.h" #include "localmem.h" #include "sig.h" #include "fof.h" +static const struct fofPos FOF_POS_INIT = {NULL, 0, 0, 0, NULL}; + struct fofRecord /* This holds a record of an index file. */ { bits32 offset; /* Start offset within file. Must be first element.*/ bits32 size; /* Sizer within file. */ UBYTE fileIx; /* Which file it's in. */ char name[1]; /* Dynamically allocated to fit actual size. */ }; struct fof /* Manage a file offset file - an index which includes the file, * the offset, and the size of each item. */ { char *name; /* Name of fof given to fofOpen. */ char *relDir; /* Directory to apply to index files. */ @@ -278,48 +280,48 @@ } boolean fofFind(struct fof *fof, char *name, struct fofPos *retPos) /* Find element corresponding with name. Returns FALSE if no such name * in the index file. */ { return fofSearch(fof, name, strlen(name), FALSE, retPos); } void *fofFetch(struct fof *fof, char *name, int *retSize) /* Lookup element in index, allocate memory for it, and read * it. Returns buffer with element in it, which should be * freeMem'd when done. Aborts if element isn't there. */ { -struct fofPos pos; +struct fofPos pos = FOF_POS_INIT; void *s; if (!fofFind(fof, name, &pos)) errAbort("Couldn't find %s in %s", name, fof->name); s = needLargeMem(pos.size); fseek(pos.f, pos.offset, SEEK_SET); mustRead(pos.f, s, pos.size); *retSize = pos.size; return s; } char *fofFetchString(struct fof *fof, char *name, int *retSize) /* Lookup element in index, allocate memory for it, read it. * Returns zero terminated string with element in it, which * should be freeMem'd when done. Aborts if element isn't there. */ { -struct fofPos pos; +struct fofPos pos = FOF_POS_INIT; char *s; if (!fofFind(fof, name, &pos)) errAbort("Couldn't find %s in %s", name, fof->name); s = needLargeMem(pos.size+1); fseek(pos.f, pos.offset, SEEK_SET); mustRead(pos.f, s, pos.size); s[pos.size] = 0; *retSize = pos.size; return s; } /* ------------------- Batch read ------------------------*/ static int cmpOnKey(const void *va, const void *vb) /* Comparison function for qsort on an array of offset pointers.