568ea79b380d977ebc8f3f35cb5cb20130c746c2 max Fri Aug 24 18:46:16 2018 -0700 fixing another barchart crash, when the size does not include the trailing newline, no redmine diff --git src/hg/hgc/barChartClick.c src/hg/hgc/barChartClick.c index 7834434..f1fc9a6 100644 --- src/hg/hgc/barChartClick.c +++ src/hg/hgc/barChartClick.c @@ -158,46 +158,50 @@ while (lineFileChopNext(lf, words, sizeof words)) { hashAdd(sampleHash, words[0], words[1]); sampleCt++; } lineFileClose(&lf); // Open matrix file struct udcFile *f = udcFileOpen(dataFile, NULL); // Get header line with sample ids char *header = udcReadLine(f); int wordCt = sampleCt+1; // initial field is label or empty char **samples; AllocArray(samples, wordCt); -chopByWhite(header, samples, wordCt); +int gotSampleCt = chopByWhite(header, samples, wordCt); +if (gotSampleCt!=wordCt) + warn("Expected %d columns in matrix based on categories file, but got %d", wordCt, gotSampleCt); // Get data values // Format: id, category, extras bits64 offset = (bits64)bed->_dataOffset; bits64 size = (bits64)bed->_dataLen; udcSeek(f, offset); bits64 seek = udcTell(f); if (udcTell(f) != offset) warn("UDC seek mismatch: expecting %Lx, got %Lx. ", offset, seek); -char *buf = needMem(size); +char *buf = needMem(size+1); bits64 count = udcRead(f, buf, size); if (count != size) warn("UDC read mismatch: expecting %Ld bytes, got %Ld. ", size, count); + char **vals; AllocArray(vals, wordCt); +buf[size]=0; // in case that size does not include the trailing newline int gotWordCt = chopByWhite(buf, vals, wordCt); if (gotWordCt != wordCt) warn("Matrix format error: expected %d words, but got %d. File %s, on line for gene %s, at offset %llu, with line lenght %llu", wordCt, gotWordCt, dataFile, bed->name, offset, size); udcFileClose(&f); // Construct list of sample data with category struct barChartItemData *sampleVals = NULL, *data = NULL; int i; for (i=1; i<wordCt && samples[i] != NULL; i++) { char *sample = samples[i]; char *categ = (char *)hashFindVal(sampleHash, sample); if (categ == NULL) warn("barChart track %s: unknown category for sample %s", tdb->track, sample);