int Read1NVTFrame(t_sdif_fileinfo *x, FILE *f, char *name, SDIF_FrameHeader *fhp) { // Just read the frame header, so go through the matrices looking for 1NVTs to print SDIFresult r; int i, sz; SDIF_MatrixHeader mh; char *buf; for (i = 0; i < fhp->matrixCount; ++i) { if (r = SDIF_ReadMatrixHeader(&mh, f)) { object_error((t_object *)x, NAME ": error reading matrix header: %s", SDIF_GetErrorString(r)); return 0; } if (SDIF_Char4Eq("1NVT", mh.matrixType) && mh.matrixDataType == SDIF_UTF8) { sz = SDIF_GetMatrixDataSize(&mh); buf = (char *) getbytes(sz); if (buf == 0) { object_error((t_object *)x, NAME ": out of memory; can't read name/value table"); return 0; } if (r = SDIF_ReadMatrixData((void *) buf, f, &mh)) { object_error((t_object *)x, NAME ": error reading 1NVT matrix data: %s", SDIF_GetErrorString(r)); return 0; } //post("Name/value table:"); //post("%s", buf); SDIFfileinfo_output1NVT(x, buf, fhp); freebytes(buf, sz); } else { if (SDIF_Char4Eq("1NVT", mh.matrixType)) { object_post((t_object *)x, NAME ": 1NVT matrix has unexpected matrix data type 0x%x; skipping", mh.matrixDataType); } if (r = SDIF_SkipMatrix(&mh, f)) { object_error((t_object *)x, NAME ": error skipping 1NVT matrix: %s", SDIF_GetErrorString(r)); return 0; } } } }
SDIFresult SDIFmem_ReadFrameContents(SDIF_FrameHeader *head, FILE *f, SDIFmem_Frame *putithere) { /* The user has just read the header for this frame; now we have to read all the frame's matrices, put them in an SDIFmem_Matrix linked list, and then stuff everything into an SDIFmem_Frame. */ SDIFresult r; SDIFmem_Frame result; SDIFmem_Matrix matrix; int i, sz; SDIFmem_Matrix *prevNextPtr; result = (SDIFmem_Frame) (*my_malloc)(sizeof(*result)); if (result == 0) { return ESDIF_OUT_OF_MEMORY; } result->header = *head; result->prev = 0; result->next = 0; result->matrices = 0; prevNextPtr = &(result->matrices); for (i = 0; i < head->matrixCount; ++i) { matrix = SDIFmem_CreateEmptyMatrix(); if (matrix == 0) { SDIFmem_FreeFrame(result); return ESDIF_OUT_OF_MEMORY; } /* Get the linked list pointers right. Now if we bomb out and call SDIFmem_FreeFrame(result) it will free the matrix we just allocated */ *(prevNextPtr) = matrix; prevNextPtr = &(matrix->next); matrix->next = 0; if ((r = SDIF_ReadMatrixHeader(&(matrix->header), f))!=ESDIF_SUCCESS) { SDIFmem_FreeFrame(result); return r; } sz = SDIF_GetMatrixDataSize(&(matrix->header)); if (sz == 0) { matrix->data = NULL; } else { matrix->data = (*my_malloc)(sz); if (matrix->data == NULL) { SDIFmem_FreeFrame(result); return ESDIF_OUT_OF_MEMORY; } } /* COVERITY: what if sz=0? dereferences null */ if (sz != 0) if ((r = SDIF_ReadMatrixData(matrix->data, f, &(matrix->header)))!=ESDIF_SUCCESS) { SDIFmem_FreeFrame(result); return r; } } *putithere = result; return ESDIF_SUCCESS; }