f57fc11d951807e19b20b5960e735fa50eaea279
braney
  Fri Jun 12 13:10:00 2026 -0700
Fix more warnings exposed by -O3 build across hg utils and errAbort

Continuation of the -O3 cleanup: a full clean rebuild surfaced warnings in
many programs whose objects had not been recompiled before.  Most are the same
mechanical patterns as the first batch (strncpy -> safecpy/memcpy, sprintf ->
safef), plus a few that needed more thought:

- errAbort.h: mark errAbort/vaErrAbort/errnoAbort/noWarnAbort as noreturn.
They provably never return (longjmp or exit; the existing "to make compiler
happy" exit(-1) in noWarnAbort confirms the intent), and this lets GCC prune
the impossible null paths after an errAbort guard, fixing false-positive
null-deref / overread warnings in mafAddIRows, mafAddIRowsStream and
phyloPlace with no source change to those files.
- altSplice.c (hgGene): real one-element stack buffer overflow.  makeGrayShades
writes shadesOfGray[maxShade+1], but the caller declared shadesOfGray[9] with
maxShade=8.  Grow the array to [10] (maxShade stays 8); behavior unchanged.
- hgc.c bedPrintPos: ~60 callers pass a track-specific struct cast to
(struct bed *) and read only its bed-compatible leading fields.  At -O3
-Warray-bounds flags the casts because the real object is smaller than
struct bed; the reads are safe by the bed-layout convention, so suppress
-Warray-bounds around just that function.
- mafsInRegion.c: chromFromSrc returns strchr(src,'.')+1, which GCC mis-sizes
as a 0-byte region when handed to strcmp via sameString/differentString;
suppress the false-positive -Wstringop-overread around extractMafs.
- sanger22gtf.c, bottleneck.c: put the printf/fprintf in the else of the
NULL guard so -Wformat-overflow (which runs before the noreturn-based
pruning) can see the argument is non-null.

safecpy/memcpy/safef conversions: basicBed already done earlier; here
haplotypes (memcpy of the original pointer pun), gbToFaRa, motifSig,
hgClonePos, featureBits, libScan, hgGoldGapGl, hgSoftPromoter, mafClick,
mafAddQRows, hgc.c, stanToBedAndExpRecs, bedUp, faSplit, trfBig,
splitFaIntoContigs, aladdin, ameme.

A full clean tree now builds with no warnings at -O3.

refs #37761

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

diff --git src/hg/splitFaIntoContigs/splitFaIntoContigs.c src/hg/splitFaIntoContigs/splitFaIntoContigs.c
index 35aec334932..886ec6e2702 100644
--- src/hg/splitFaIntoContigs/splitFaIntoContigs.c
+++ src/hg/splitFaIntoContigs/splitFaIntoContigs.c
@@ -225,31 +225,31 @@
 fclose(fp);
 }
 
 void writeChromAgpFile(char *chromName, struct agpData *startAgpData, char *destDir)
 /*
 Writes the agp file out for a single chromsome
 
 param chromName - The name of the chromsome.
 param startGap - Pointer to the dna gap or fragment at which we are starting to
  write data. The data will include the contents of this gap/frag.
 param destDir - The destination dir to which to write the agp file.
  */
 {
 char filename[DEFAULT_PATH_SIZE];
 
-sprintf(filename, "%s/%s.agp", destDir, chromName);
+safef(filename, sizeof(filename), "%s/%s.agp", destDir, chromName);
 printf("Writing chromosome agp file %s\n", filename);
 writeAgpFile(chromName, startAgpData, filename);
 }
 
 void writeSuperContigAgpFile(struct agpData *startAgpData, struct agpData *endAgpData, char *filename, int sequenceNum)
 /*
 Creates an agp file containing the contents of a supercontig in agp format.
 
 param startAgpData - Pointer to the dna gap or fragment at which we are starting to
  write data. The data will include the contents of this gap/frag.
 param endAgpData - Pointer to the dna gap or fragment at which we are stopping to
  write data. The data will include the contents of this gap/frag.
 param filename - The file name to which to write.
 param sequenceNum - The 1-based number of this clone supercontig in the chromsome.
  */
@@ -258,31 +258,31 @@
 writeAgpFile( endAgpData->data.pGap->chrom, startAgpData, filename);
 }
 
 void writeChromFaFile(char *chromName, char *dna, int dnaSize, char *destDir)
 /*
 Writes the contents of a single chromsome out to a file in FASTA format.
 
 param chromName - The name of the chromosome for which we are writing
  the fa file.
 param dna - Pointer to the dna array.
 param dnaSize - The size of the dna array.
  */
 {
 char filename [DEFAULT_PATH_SIZE];
 
-sprintf(filename, "%s/%s.fa", destDir, chromName);
+safef(filename, sizeof(filename), "%s/%s.fa", destDir, chromName);
 printf("Writing fa file %s for chromosome %s\n", filename, chromName);
 faWrite(filename, chromName, dna, dnaSize);
 }
 
 void writeSuperContigFaFile(DNA *dna, struct agpData *startData, struct agpData *endData, char *filename, int sequenceNum)
 /*
 Creates a fasta file containing the contents of a supercontig in FASTA format.
 
 param dna - Pointer to the dna array.
 param startData - Pointer to the dna gap or fragment at which we are starting to
  write data. The data will include the contents of this gap/frag.
 param end - Pointer to the dna gap or fragment at which we are stopping to
  write data. The data will include the contents of this gap/frag.
 param filename - The file name to which to write.
 param sequenceNum - The 1-based number of this clone supercontig in the chromsome.