annotate liszt.cpp @ 411:ad2206c24986 api-inversion

Fix a memory corruption bug. When allocating the adb_t in audiodb_open(), zero the memory; then we're not going to try to free() or delete some arbitrary uninitialized thing if the thing that we're opening turns out not to be an audiodb database.
author mas01cr
date Thu, 11 Dec 2008 08:54:06 +0000
parents 4ded52b104e6
children e18843dc0aea
rev   line source
mas01cr@386 1 #include "audioDB.h"
mas01cr@386 2
mas01cr@386 3 void audioDB::liszt(const char* dbName, unsigned offset, unsigned numLines, adb__lisztResponse* adbLisztResponse){
mas01cr@386 4 if(!dbH) {
mas01cr@386 5 initTables(dbName, 0);
mas01cr@386 6 }
mas01cr@386 7
mas01cr@386 8 assert(trackTable && fileTable);
mas01cr@386 9
mas01cr@386 10 if(offset>dbH->numFiles){
mas01cr@386 11 char tmpStr[MAXSTR];
mas01cr@386 12 sprintf(tmpStr, "numFiles=%u, lisztOffset=%u", dbH->numFiles, offset);
mas01cr@386 13 error("listKeys offset out of range", tmpStr);
mas01cr@386 14 }
mas01cr@386 15
mas01cr@386 16 if(!adbLisztResponse){
mas01cr@386 17 for(Uns32T k=0; k<numLines && offset+k<dbH->numFiles; k++){
mas01cr@386 18 fprintf(stdout, "[%d] %s (%d)\n", offset+k, fileTable+(offset+k)*O2_FILETABLE_ENTRY_SIZE, trackTable[offset+k]);
mas01cr@386 19 }
mas01cr@386 20 }
mas01cr@386 21 else{
mas01cr@386 22 adbLisztResponse->result.Rkey = new char*[numLines];
mas01cr@386 23 adbLisztResponse->result.Rlen = new unsigned int[numLines];
mas01cr@386 24 Uns32T k = 0;
mas01cr@386 25 for( ; k<numLines && offset+k<dbH->numFiles; k++){
mas01cr@386 26 adbLisztResponse->result.Rkey[k] = new char[MAXSTR];
mas01cr@386 27 snprintf(adbLisztResponse->result.Rkey[k], O2_MAXFILESTR, "%s", fileTable+(offset+k)*O2_FILETABLE_ENTRY_SIZE);
mas01cr@386 28 adbLisztResponse->result.Rlen[k] = trackTable[offset+k];
mas01cr@386 29 }
mas01cr@386 30 adbLisztResponse->result.__sizeRkey = k;
mas01cr@386 31 adbLisztResponse->result.__sizeRlen = k;
mas01cr@386 32 }
mas01cr@386 33
mas01cr@386 34 }