60079bc1898e003d9f1397176baaee00e431b011
jcasper
  Tue Mar 10 14:36:41 2020 -0700
Changes to support better chr mappings in .hic files depended on a non-NULL assembly name,
which was not previously assumed.  Fixing what I broke, refs #24988

diff --git src/hg/lib/hic.c src/hg/lib/hic.c
index b7ea44f..1552570 100644
--- src/hg/lib/hic.c
+++ src/hg/lib/hic.c
@@ -11,31 +11,31 @@
 #include "hash.h"
 #include "chromAlias.h"
 #include "interact.h"
 
 void mangleName(char *ucscName, char mangledUcscName[], int size)
 /* Generate a version of an assembly's chromosome name that matches
  * the mangling performed by the Juicer .hic creation tool (strip any initial
  * "chr" and capitalize the rest). */
 {
     int offset = 0;
     char workingName[size];
     safef(workingName, sizeof(workingName), "%s", ucscName);
     touppers(workingName);
     if (startsWith("CHR", workingName))
         offset = 3;
-    strncpy(mangledUcscName, workingName+offset, size-offset);
+    safencpy(mangledUcscName, size, workingName+offset, strlen(workingName+offset));
 }
 
 
 char *hicLoadHeader(char *filename, struct hicMeta **header, char *ucscAssembly)
 /* Create a hicMeta structure for the supplied Hi-C file.  If
  * the return value is non-NULL, it points to a string containing
  * an error message that explains why the retrieval failed. */
 {
 char *genome;
 char **chromosomes, **bpResolutions, **attributes;
 int *chromSizes, nChroms, nBpRes, nAttributes;
 
 char *errMsg = CstrawHeader(filename, &genome, &chromosomes, &chromSizes, &nChroms, &bpResolutions, &nBpRes, NULL, NULL, &attributes, &nAttributes);
 if (errMsg != NULL)
     return errMsg;
@@ -44,31 +44,33 @@
 AllocVar(newMeta);
 newMeta->fileAssembly = genome;
 newMeta->nRes = nBpRes;
 newMeta->resolutions = bpResolutions;
 newMeta->nChroms = nChroms;
 newMeta->chromNames = chromosomes;
 newMeta->chromSizes = chromSizes;
 newMeta->ucscToAlias = NULL;
 newMeta->ucscAssembly = cloneString(ucscAssembly);
 newMeta->filename = cloneString(filename);
 newMeta->attributes = attributes;
 newMeta->nAttributes = nAttributes;
 
 *header = newMeta;
 
-struct slName *ucscNameList = hAllChromNames(newMeta->ucscAssembly), *ucscName = NULL;
+struct slName *ucscNameList = NULL, *ucscName = NULL;
+if (newMeta->ucscAssembly != NULL)
+    ucscNameList = hAllChromNames(newMeta->ucscAssembly);
 struct hash *ucscToChromAlias = NULL;
 if ((newMeta->ucscAssembly != NULL) && !trackHubDatabase(ucscAssembly))
     ucscToChromAlias = chromAliasMakeReverseLookupTable(newMeta->ucscAssembly);
 
 struct slName *hicChromNames = slNameListFromStringArray(chromosomes, nChroms);
 struct hash *hicChromHash = hashSetFromSlNameList(hicChromNames);
 struct hash *ucscToHicName = newHash(0);
 
 // For each UCSC chrom name, try to find a .hic file chromosome to fetch annotation from.
 for (ucscName = ucscNameList; ucscName != NULL; ucscName = ucscName->next)
     {
     char mangledName[2048];
     mangleName(ucscName->name, mangledName, sizeof(mangledName));
     if (hashLookup(hicChromHash, ucscName->name))
         hashAdd(ucscToHicName, ucscName->name, cloneString(ucscName->name));