fb50a1cca3a117bb964c43196671142484b13bf9 braney Fri Jun 12 12:10:47 2026 -0700 lib jkOwnLib hg/lib: fix warnings exposed by -O3 build At -O3 GCC does more inlining and interprocedural range analysis, which surfaces several warnings that -O -g never triggered. With -Werror these break the build, so fix them ahead of switching the default to -O3. - bamFile.c: move setenv() into the else of its NULL guard so it is not reachable with a NULL argument (-Wnonnull, seen via inlining of bamFetch). - basicBed.c, wormdna.c, bedDetail.c, customFactory.c, hdb.c, qaSeq.c: replace strncpy() with safecpy() where the result must be terminated (-Wstringop-truncation). - htmshell.c: use memcpy() for the intentional exact-length, non-terminated copy (-Wstringop-truncation). - obscure.c: compute the comma groups in sprintLongWithCommas() with % 1000 so the compiler can see each %03lld argument is bounded (-Wformat-overflow). - crudeali.c: do the endian type-pun through a union so strict-aliasing analysis no longer reports the value as uninitialized (-Wuninitialized). - jksql.c: wrap a possibly-NULL database name in naForNull() before passing it to %s (-Wformat-overflow). refs #37761 Co-Authored-By: Claude Opus 4.8 (1M context) diff --git src/lib/wormdna.c src/lib/wormdna.c index 5e409ad8b36..0997369ed57 100644 --- src/lib/wormdna.c +++ src/lib/wormdna.c @@ -498,31 +498,31 @@ boolean wormIsOrfName(char *in) /* Check to see if the input is formatted correctly to be * an ORF. */ { return strchr(in, '.') != NULL; } boolean wormIsGeneName(char *name) /* See if it looks like a worm gene name - that is * abc-12 * letters followed by a dash followed by a number. */ { char buf[128]; int partCount; -strncpy(buf, name, sizeof(buf)); +safecpy(buf, sizeof(buf), name); partCount = chopString(buf, "-", NULL, 0); if (partCount == 2) { char *parts[2]; chopString(buf, "-", parts, 2); return isAllAlpha(parts[0]) && isAllDigits(parts[1]); } else { return FALSE; } } struct slName *wormGeneToOrfNames(char *name) /* Returns list of cosmid.N type ORF names that are known by abc-12 type name. */ @@ -855,31 +855,31 @@ } /* This handles case where the range is larger than the chromosome. */ if (*pStart < 0) *pStart = 0; } boolean wormParseChromRange(char *in, char **retChromId, int *retStart, int *retEnd) /* Chop up a string representation of a range within a chromosome and put the * pieces into the return variables. Return FALSE if it isn't formatted right. */ { char *words[5]; int wordCount; char *chromId; char buf[128]; -strncpy(buf, in, sizeof(buf)); +safecpy(buf, sizeof(buf), in); wordCount = chopString(buf, "- \t\r\n:", words, ArraySize(words)); if (wordCount != 3) return FALSE; chromId = wormOfficialChromName(words[0]); if (chromId == NULL) return FALSE; if (!isdigit(words[1][0]) || !isdigit(words[2][0])) return FALSE; *retChromId = chromId; *retStart = atoi(words[1]); *retEnd = atoi(words[2]); wormClipRangeToChrom(chromId, retStart, retEnd); return TRUE; }