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/jkOwnLib/crudeali.c src/jkOwnLib/crudeali.c index 67d06f27488..43d44339cd2 100644 --- src/jkOwnLib/crudeali.c +++ src/jkOwnLib/crudeali.c @@ -458,34 +458,35 @@ } static int makeHits8(struct fastProber *fp, struct nt4Seq *target, struct crudeHit *hits, int maxHitCount) /* Scan entire target for hits to probe. */ { bits16 *bases = (bits16*)target->bases; struct probeTile **hash = fp->hash; struct probeTile *pbt; int hitCount = 0; int i; int baseWordCount = (target->baseCount/caTileSize); int tOffset = 0; -/* Handle big/little endian problem. */ -bits32 endianTest = 0x12345678; -bits16 *endianPt = (bits16*)(void*)(&endianTest); -boolean needSwap = (*endianPt == 0x5678); +/* Handle big/little endian problem. Use a union for the type-punning so we + * don't run afoul of strict-aliasing analysis at -O3. */ +union { bits32 whole; bits16 half[2]; } endianTest; +endianTest.whole = 0x12345678; +boolean needSwap = (endianTest.half[0] == 0x5678); int swapOffset[2]; int swapIx = 0; /* Every so often we throw out singleton hits. The variables below * manage this. */ int compactWindowSizePower = 10; int compactWindowSize = (1<probeSize+4); int compactBufSize = (compactBufIntSize*sizeof(short)); short *compactDiagBuf = needLargeMem(compactBufSize); if (needSwap)