2d503f8823cbee3db01fc029b2ae42701e36469b
chmalee
  Fri Sep 10 11:46:47 2021 -0700
Fix crash when hgvsParseTerm fails to find a match to a psuedo hgvs term, refs #28147

diff --git src/hg/lib/hgHgvs.c src/hg/lib/hgHgvs.c
index 1c78e6a..9cbe1ba 100644
--- src/hg/lib/hgHgvs.c
+++ src/hg/lib/hgHgvs.c
@@ -930,55 +930,59 @@
     int len = substrs[geneSymbolIx].rm_eo - substrs[geneSymbolIx].rm_so;
     char geneSymbol[len+1];
     safencpy(geneSymbol, sizeof(geneSymbol), term, len);
     struct slName *npAccList = npForGeneSymbol(db, geneSymbol);
     if (npAccList != NULL)
         {
         struct slName *npItem = NULL;
         for (npItem = npAccList; npItem != NULL; npItem = npItem->next)
             {
             char *npAcc = npItem->name;
             // Make it a real HGVS term with the NP and pass that on to the usual parser.
             int descStartIx = 2;
             char *description = term + substrs[descStartIx].rm_so;
             struct dyString *npTerm = dyStringCreate("%s(%s):p.%s",
                                                      npAcc, geneSymbol, description);
-            slAddHead(&hgvs, hgvsParseTerm(npTerm->string));
+            struct hgvsVariant *newTerm = hgvsParseTerm(npTerm->string);
+            if (newTerm)
+                slAddHead(&hgvs, newTerm);
             dyStringFree(&npTerm);
             }
         }
     }
 else if (regexMatchSubstr(term, pseudoHgvsGeneSymbolProtPosExp, substrs, ArraySize(substrs)))
     {
     int len = substrs[geneSymbolIx].rm_eo - substrs[geneSymbolIx].rm_so;
     char geneSymbol[len+1];
     safencpy(geneSymbol, sizeof(geneSymbol), term, len);
     struct slName *npAccList = npForGeneSymbol(db, geneSymbol);
     if (npAccList != NULL)
         {
         struct slName *npItem = NULL;
         for (npItem = npAccList; npItem != NULL; npItem = npItem->next)
             {
             char *npAcc = npItem->name;
             // Only position was provided, no change.  Look up ref base and make a synonymous subst
             // so it's parseable HGVS.
             int posIx = 2;
             int pos = regexSubstringInt(term, substrs[posIx]);
             char refBase = refBaseForNp(db, npAcc, pos);
             struct dyString *npTerm = dyStringCreate("%s(%s):p.%c%d=",
                                                      npAcc, geneSymbol, refBase, pos);
-            slAddHead(&hgvs, hgvsParseTerm(npTerm->string));
+            struct hgvsVariant *newTerm = hgvsParseTerm(npTerm->string);
+            if (newTerm)
+                slAddHead(&hgvs, newTerm);
             dyStringFree(&npTerm);
             }
         }
     }
 else if (regexMatchSubstr(term, pseudoHgvsGeneSympolCDotPosExp, substrs, ArraySize(substrs)))
     {
     int len = substrs[geneSymbolIx].rm_eo - substrs[geneSymbolIx].rm_so;
     char geneSymbol[len+1];
     safencpy(geneSymbol, sizeof(geneSymbol), term, len);
     char *nmAcc = nmForGeneSymbol(db, geneSymbol);
     if (isNotEmpty(nmAcc))
         {
         // Make it a real HGVS term with the NM and pass that on to the usual parser.
         int descStartIx = regexSubstrMatched(substrs[2]) ? 2 : 3;
         char *description = term + substrs[descStartIx].rm_so;