799b4fefa8e3e5e1453ff8d79e7d1f23f3812546 angie Thu Dec 22 13:12:00 2016 -0800 Piggyback on my last commit: get the real wordCount from chopString because the last separator might not have anything after it (null idWord -> SEGV). Trim spaces on the way into idHash as well as on the way out. refs #18586 diff --git src/hg/hgTables/joining.c src/hg/hgTables/joining.c index 0b2e94b..c1bd3ab 100644 --- src/hg/hgTables/joining.c +++ src/hg/hgTables/joining.c @@ -653,31 +653,33 @@ if (hashLookup(idHash, id)) { if (jrRowAdd(joined, row, fieldCount, keyCount) == NULL) break; } } else { // chop id column by jf->separator if necessary int sepCount = 0; if (jf && isNotEmpty(jf->separator)) sepCount = countChars(id, jf->separator[0]); int wordCount = sepCount + 1; char *idWords[wordCount]; if (wordCount > 1) - chopString(id, jf->separator, idWords, ArraySize(idWords)); + // There may or may not be a word past the final separator, + // So get the real wordCount here: + wordCount = chopString(id, jf->separator, idWords, ArraySize(idWords)); else idWords[0] = id; int i; for (i = 0; i < wordCount; i++) { struct slName *chopBefore = jf ? jf->chopBefore : NULL; struct slName *chopAfter = jf ? jf->chopAfter : NULL; idWords[i] = chopKey(chopBefore, chopAfter, trimSpaces(idWords[i])); struct hashEl *bucket; for (bucket = hashLookup(idHash, idWords[i]); bucket != NULL; bucket = hashLookupNext(bucket)) { jr = bucket->val; jr->hitThisTable = TRUE; jrRowExpand(joined, jr, row, @@ -746,31 +748,31 @@ { int hashSize = digitsBaseTwo(joined->rowCount); struct hash *hash = NULL; struct joinedRow *jr; if (hashSize > 20) hashSize = 20; hash = newHash(hashSize); for (jr = joined->rowList; jr != NULL; jr = jr->next) { struct slName *key; for (key = jr->keys[keyIx]; key != NULL; key = key->next) { if (jf->separator == NULL) { - char *s = chopKey(jf->chopBefore, jf->chopAfter, key->name); + char *s = chopKey(jf->chopBefore, jf->chopAfter, trimSpaces(key->name)); if (s[0] != 0) hashAdd(hash, s, jr); } else { char *s = key->name, *e; char sep = jf->separator[0]; while (s != NULL && s[0] != 0) { e = strchr(s, sep); if (e != NULL) *e++ = 0; s = chopKey(jf->chopBefore, jf->chopAfter, s); if (s[0] != 0) hashAdd(hash, s, jr);