e81403a315a24af601884b8a19e89bcecc92f267
galt
  Sat Dec 8 20:04:28 2018 -0800
Fixing hFindSplitTable and its use. Standard size, give real string size so no undetected overflows. Test result and abort if not found. Avoids SQL errors that otherwise will popup. Handles uninitialzed stack better for the output name. refs #22596.

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 8155e8f..0d02cf6 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -3328,45 +3328,53 @@
 else if (hti->hasCDS)
     return 8;
 else if (hti->strandField[0] != 0)
     return 6;
 else if (hti->scoreField[0] != 0)
     return 5;
 else if (hti->nameField[0] != 0)
     return 4;
 else
     return 3;
 }
 
 
 
 boolean hFindSplitTable(char *db, char *chrom, char *rootName,
-	char retTableBuf[HDB_MAX_TABLE_STRING], boolean *hasBin)
+	char *retTableBuf, int tableBufSize, boolean *hasBin)
 /* Find name of table in a given database that may or may not
- * be split across chromosomes. Return FALSE if table doesn't exist.  */
+ * be split across chromosomes. Return FALSE if table doesn't exist. 
+ *
+ * Do not ignore the return value. 
+ * This function does NOT tell you whether or not the table is split. 
+ * It tells you if the table exists. */
 {
 struct hTableInfo *hti = hFindTableInfo(db, chrom, rootName);
 if (hti == NULL)
+    {
+    // better than uninitialized stack value if caller ignores return value.
+    retTableBuf[0] = 0;
     return FALSE;
+    }
 if (retTableBuf != NULL)
     {
     if (chrom == NULL)
 	chrom = hDefaultChrom(db);
     if (hti->isSplit)
-	safef(retTableBuf, HDB_MAX_TABLE_STRING, "%s_%s", chrom, rootName);
+	safef(retTableBuf, tableBufSize, "%s_%s", chrom, rootName);
     else
-	safef(retTableBuf, HDB_MAX_TABLE_STRING, "%s", rootName);
+	safef(retTableBuf, tableBufSize, "%s", rootName);
     }
 if (hasBin != NULL)
     *hasBin = hti->hasBin;
 return TRUE;
 }
 
 struct slName *hSplitTableNames(char *db, char *rootName)
 /* Return a list of all split tables for rootName, or of just rootName if not
  * split, or NULL if no such tables exist. */
 {
 struct hash *hash = NULL;
 struct hashEl *hel = NULL;
 
 hash = tableListGetDbHash(db);
 hel = hashLookup(hash, rootName);