Remove compiler warnings so SWORD will compile with -Wall -Werror Index: debian/src/mgr/filemgr.cpp =================================================================== --- debian.orig/src/mgr/filemgr.cpp +++ debian/src/mgr/filemgr.cpp @@ -408,7 +408,7 @@ int FileMgr::createPathAndFile(const cha int FileMgr::copyFile(const char *sourceFile, const char *targetFile) { - int sfd, dfd, len; + int sfd, dfd, len; char buf[4096]; if ((sfd = ::open(sourceFile, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) < 1) Index: debian/src/utilfuns/zlib/untgz.c =================================================================== --- debian.orig/src/utilfuns/zlib/untgz.c +++ debian/src/utilfuns/zlib/untgz.c @@ -13,6 +13,8 @@ #include #ifdef unix # include +# include +# include #else # include # include @@ -80,7 +82,7 @@ union tar_buffer { enum { TGZ_EXTRACT = 0, TGZ_LIST }; -static char *TGZfname OF((const char *)); +// static char *TGZfname OF((const char *)); void TGZnotfound OF((const char *)); int getoct OF((char *, int)); @@ -105,22 +107,23 @@ static char *TGZprefix[] = { "\0", ".tgz /* Return the real name of the TGZ archive */ /* or NULL if it does not exist. */ -static char *TGZfname OF((const char *fname)) -{ - static char buffer[1024]; - int origlen,i; - - strcpy(buffer,fname); - origlen = strlen(buffer); - - for (i=0; TGZprefix[i]; i++) - { - strcpy(buffer+origlen,TGZprefix[i]); - if (access(buffer,F_OK) == 0) - return buffer; - } - return NULL; -} +// COMMENTED OUT 20090516 for SWORD +// static char *TGZfname OF((const char *fname)) +// { +// static char buffer[1024]; +// int origlen,i; +// +// strcpy(buffer,fname); +// origlen = strlen(buffer); +// +// for (i=0; TGZprefix[i]; i++) +// { +// strcpy(buffer+origlen,TGZprefix[i]); +// if (access(buffer,F_OK) == 0) +// return buffer; +// } +// return NULL; +// } /* error message for the filename */ @@ -277,7 +280,7 @@ int untar (gzFile in, const char *dest) int remaining = 0; FILE *outfile = NULL; char fname[BLOCKSIZE]; - time_t tartime; + time_t tartime = 0; while (1) { len = gzread(in, &buffer, BLOCKSIZE); Index: debian/tests/testblocks.cpp =================================================================== --- debian.orig/tests/testblocks.cpp +++ debian/tests/testblocks.cpp @@ -29,14 +29,18 @@ using namespace sword; void addEntry(EntriesBlock *eb) { string input; string body; - char line[1024]; + char line[1024], *c; std::cout << "\nEnter new Entry's text. '.' on an empty line to finish:\n"; do { std::cout << "> "; - fgets(line, 1000, stdin); - input = line; - if (input.compare(".")) - body.append(input); + c = fgets(line, 1000, stdin); + if (c == NULL) { + std::cerr << "ERROR: fgets failed during addEntry\n"; + } else { + input = line; + if (input.compare(".")) + body.append(input); + } } while (input.compare(".")); std::cout << "Adding new entry. Index is: " << eb->addEntry(body.c_str()) << "\n\n"; @@ -72,29 +76,33 @@ int main(int argc, char **argv) { EntriesBlock *eb = new EntriesBlock(); string input; - char line[1024]; + char line[1024], *c; std::cout << "Initial entry count should be 0: " << eb->getCount() << "\n"; do { std::cout << "[" << eb->getCount() << "] > "; - fgets(line, 1000, stdin); - input = line; - if (input.length() > 0) { - switch (input[0]) { - case 'a': addEntry(eb); break; - case 'p': printEntry(eb, atoi(input.c_str()+1)); break; - case 'r': removeEntry(eb, atoi(input.c_str()+1)); break; - case 's': printSize(eb); break; - case 'q': break; - case '?': - default: - std::cout << "\n a - add a new entry\n"; - std::cout << " p - print entry\n"; - std::cout << " r - remove entry\n"; - std::cout << " s - print size of raw data\n"; - std::cout << " q - quit\n\n"; - break; + c = fgets(line, 1000, stdin); + if (c == NULL) { + std::cerr << "ERROR: fgets failed in main\n"; + } else { + input = line; + if (input.length() > 0) { + switch (input[0]) { + case 'a': addEntry(eb); break; + case 'p': printEntry(eb, atoi(input.c_str()+1)); break; + case 'r': removeEntry(eb, atoi(input.c_str()+1)); break; + case 's': printSize(eb); break; + case 'q': break; + case '?': + default: + std::cout << "\n a - add a new entry\n"; + std::cout << " p - print entry\n"; + std::cout << " r - remove entry\n"; + std::cout << " s - print size of raw data\n"; + std::cout << " q - quit\n\n"; + break; + } } } } Index: debian/utilities/stepdump.cpp =================================================================== --- debian.orig/utilities/stepdump.cpp +++ debian/utilities/stepdump.cpp @@ -158,33 +158,56 @@ int main(int argc, char **argv) { void readVersion(int fd, Version *versionRecord) { + int r; cout << "\n\nReading Version Record (" << 16/*sizeof(struct Version)*/ << " bytes)\n\n"; // DO NOT USE BECAUSE OF RECORD BYTE ALIGNMENT PROBLEMS // read(fd, &versionRecord, sizeof(struct Version)); cout << "Version Record Information\n"; - read(fd, &(versionRecord->versionRecordSize), 2); + r = read(fd, &(versionRecord->versionRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tversionRecordSize: " << versionRecord->versionRecordSize << "\n"; - read(fd, &(versionRecord->publisherID), 2); + r = read(fd, &(versionRecord->publisherID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tpublisherID: " << versionRecord->publisherID << "\n"; - read(fd, &(versionRecord->bookID), 2); + r = read(fd, &(versionRecord->bookID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tbookID: " << versionRecord->bookID << "\n"; - read(fd, &(versionRecord->setID), 2); + r = read(fd, &(versionRecord->setID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tsetID: " << versionRecord->setID << "\n"; - read(fd, &(versionRecord->conversionProgramVerMajor), 1); + r = read(fd, &(versionRecord->conversionProgramVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tconversionProgramVerMajor: " << (int)versionRecord->conversionProgramVerMajor << "\n"; - read(fd, &(versionRecord->conversionProgramVerMinor), 1); + r = read(fd, &(versionRecord->conversionProgramVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tconversionProgramVerMinor: " << (int)versionRecord->conversionProgramVerMinor << "\n"; - read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); + r = read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tleastCompatSTEPVerMajor: " << (int)versionRecord->leastCompatSTEPVerMajor << "\n"; - read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); + r = read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tleastCompatSTEPVerMinor: " << (int)versionRecord->leastCompatSTEPVerMinor << "\n"; - read(fd, &(versionRecord->encryptionType), 1); + r = read(fd, &(versionRecord->encryptionType), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\tencryptionType: " << (int)versionRecord->encryptionType << "\n"; - read(fd, &(versionRecord->editionID), 1); + r = read(fd, &(versionRecord->editionID), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); cout << "\teditionID: " << (int)versionRecord->editionID << "\n"; - read(fd, &(versionRecord->modifiedBy), 2); + r = read(fd, &(versionRecord->modifiedBy), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); cout << "\tmodifiedBy: " << versionRecord->modifiedBy << "\n"; int skip = versionRecord->versionRecordSize - 16/*sizeof(struct Version*/; @@ -192,33 +215,49 @@ void readVersion(int fd, Version *versio if (skip) { cout << "\nSkipping " << skip << " unknown bytes.\n"; char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readVersion"); delete [] skipbuf; } } void readViewableHeader(int fd, ViewableHeader *viewableHeaderRecord) { - + int r; cout << "\n\nReading Viewable Header Record (" << 16/*sizeof(struct ViewableHeader)*/ << " bytes)\n\n"; // DO NOT USE BECAUSE OF RECORD BYTE ALIGNMENT PROBLEMS // read(fd, &viewableHeaderRecord, sizeof(struct ViewableHeader)); cout << "Viewable Header Record Information\n"; - read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); + r = read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); cout << "\tviewableHeaderRecordSize: " << viewableHeaderRecord->viewableHeaderRecordSize << "\n"; - read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); + r = read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); cout << "\tviewableBlocksCount: " << viewableHeaderRecord->viewableBlocksCount << "\n"; - read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); + r = read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); cout << "\tglossBlocksCount: " << viewableHeaderRecord->glossBlocksCount << "\n"; - read(fd, &(viewableHeaderRecord->compressionType), 1); + r = read(fd, &(viewableHeaderRecord->compressionType), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); cout << "\tcompressionType: " << (int)viewableHeaderRecord->compressionType << "(0 - none; 1 - LZSS)\n"; - read(fd, &(viewableHeaderRecord->reserved1), 1); + r = read(fd, &(viewableHeaderRecord->reserved1), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); cout << "\treserved1: " << (int)viewableHeaderRecord->reserved1 << "\n"; - read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); + r = read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); cout << "\tblockEntriesSize: " << viewableHeaderRecord->blockEntriesSize << "\n"; - read(fd, &(viewableHeaderRecord->reserved2), 2); + r = read(fd, &(viewableHeaderRecord->reserved2), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); cout << "\treserved2: " << viewableHeaderRecord->reserved2 << "\n"; int skip = viewableHeaderRecord->viewableHeaderRecordSize - 16/*sizeof(struct ViewableHeader)*/; @@ -226,18 +265,23 @@ void readViewableHeader(int fd, Viewable if (skip) { cout << "\nSkipping " << skip << " unknown bytes.\n"; char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readViewableHeader"); delete [] skipbuf; } } void readViewableBlockText(int fd, ViewableBlock *vb, char **buf) { + int r; unsigned long size = vb->size; *buf = new char [ ((vb->size > vb->uncompressedSize) ? vb->size : vb->uncompressedSize) + 1 ]; lseek(fd, vb->offset, SEEK_SET); - read(fd, *buf, vb->size); + r = read(fd, *buf, vb->size); + if (r != vb->size) + perror("ERROR: read failed in readViewableBlocktext"); compress->zBuf(&size, *buf); strcpy(*buf, compress->Buf()); @@ -247,30 +291,41 @@ void readViewableBlockText(int fd, Viewa void readViewableBlock(int fd, ViewableBlock *vb) { - + int r; cout << "\n\nReading Viewable Block (" << 12/*sizeof(struct ViewableHeader)*/ << " bytes)\n\n"; // DO NOT USE BECAUSE OF RECORD BYTE ALIGNMENT PROBLEMS // read(fd, &vb, sizeof(struct ViewableBlock)); cout << "Viewable Block Information\n"; - read(fd, &(vb->offset), 4); + r = read(fd, &(vb->offset), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); cout << "\toffset: " << vb->offset << "\n"; - read(fd, &(vb->uncompressedSize), 4); + r = read(fd, &(vb->uncompressedSize), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); cout << "\tuncompressedSize: " << vb->uncompressedSize << "\n"; - read(fd, &(vb->size), 4); + r = read(fd, &(vb->size), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); cout << "\tsize: " << vb->size << "\n"; } void readHeaderControlWordAreaText(int fd, char **buf) { + int r; long headerControlWordAreaSize; - read(fd, &headerControlWordAreaSize, 4); + r = read(fd, &headerControlWordAreaSize, 4); + if (r != 4) + perror("ERROR: read failed in readHeaderControlWordAreaText"); cout << "Reading Header Control Word Area (" << headerControlWordAreaSize << " bytes)\n\n"; *buf = new char [headerControlWordAreaSize + 1]; - read(fd, *buf, headerControlWordAreaSize); + r = read(fd, *buf, headerControlWordAreaSize); + if (r != headerControlWordAreaSize) + perror("ERROR: read failed in readHeaderControlWordAreaText"); (*buf)[headerControlWordAreaSize] = 0; cout << "headerControlWordArea:\n" << *buf << "\n"; Index: debian/utilities/treeidxutil.cpp =================================================================== --- debian.orig/utilities/treeidxutil.cpp +++ debian/utilities/treeidxutil.cpp @@ -53,27 +53,33 @@ void printLocalName(TreeKeyIdx *treeKey) void setLocalName(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Node Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in setLocalName\n"; treeKey->setLocalName(buf); treeKey->save(); } void assurePath(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter path: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in assurePath\n"; treeKey->assureKeyPath(buf); } void appendSibbling(TreeKeyIdx *treeKey) { if (treeKey->getOffset()) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Sibbling Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendSibbling\n"; treeKey->append(); treeKey->setLocalName(buf); treeKey->save(); @@ -83,9 +89,11 @@ void appendSibbling(TreeKeyIdx *treeKey) void appendChild(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Child Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendChild\n"; treeKey->appendChild(); treeKey->setLocalName(buf); treeKey->save(); @@ -118,11 +126,13 @@ int main(int argc, char **argv) { TreeKeyIdx root = *treeKey; std::string input; - char line[1024]; + char line[1024], *c; do { std::cout << "[" << treeKey->getText() << "] > "; - fgets(line, 1000, stdin); + c = fgets(line, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in main\n"; input = line; if (input.length() > 0) { switch (input[0]) { Index: debian/utilities/gbfidx.cpp =================================================================== --- debian.orig/utilities/gbfidx.cpp +++ debian/utilities/gbfidx.cpp @@ -53,7 +53,7 @@ char testmnt; int main(int argc, char **argv) { long pos, offset; - int num1, num2, rangemax; + int num1, num2, rangemax, w; char startflag = 0; short size; @@ -65,18 +65,30 @@ int main(int argc, char **argv) num1 = key1.Chapter(); num2 = key1.Verse(); pos = 0; - write(bfp, &pos, 4); /* Book offset for testament intros */ + w = write(bfp, &pos, 4); /* Book offset for testament intros */ + if (w != 4) + perror("ERROR: write failed in main"); pos = 4; - write(cfp, &pos, 4); /* Chapter offset for testament intro */ + w = write(cfp, &pos, 4); /* Chapter offset for testament intro */ + if (w != 4) + perror("ERROR: write failed in main"); /* Right now just zero out intros until parsing correctly */ pos = 0; size = 0; - write(vfp, &pos, 4); /* Module intro */ - write(vfp, &size, 2); - write(vfp, &pos, 4); /* Testament intro */ - write(vfp, &size, 2); + w = write(vfp, &pos, 4); /* Module intro */ + if (w != 4) + perror("ERROR: write failed in main"); + w = write(vfp, &size, 2); + if (w != 2) + perror("ERROR: write failed in main"); + w = write(vfp, &pos, 4); /* Testament intro */ + if (w != 4) + perror("ERROR: write failed in main"); + w = write(vfp, &size, 2); + if (w != 2) + perror("ERROR: write failed in main"); while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) { if (!startflag) { @@ -120,6 +132,7 @@ int main(int argc, char **argv) void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size) { + int w; long pos; short tmp; @@ -127,26 +140,48 @@ void writeidx(VerseKey &key1, VerseKey & if (key1.Verse() == 1) { // new chapter if (key1.Chapter() == 1) { // new book pos = lseek(cfp, 0, SEEK_CUR); - write(bfp, &pos, 4); + w = write(bfp, &pos, 4); + if (w != 2) + perror("ERROR: write failed in writeidx"); pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */ - write(cfp, &pos, 4); - write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/ - write(vfp, &chapsize, 2); + w = write(cfp, &pos, 4); + if (w != 2) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/ + if (w != 2) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapsize, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } pos = lseek(vfp, 0, SEEK_CUR); - write(cfp, &pos, 4); - write(vfp, &chapoffset, 4); /* Chapter intro */ - write(vfp, &chapsize, 2); + w = write(cfp, &pos, 4); + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapoffset, 4); /* Chapter intro */ + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &chapsize, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } if (key1 >= key2) { - write(vfp, &offset, 4); - write(vfp, &size, 2); + w = write(vfp, &offset, 4); + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &size, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } else { pos = 0; tmp = 0; - write(vfp, &pos, 4); - write(vfp, &tmp, 2); + w = write(vfp, &pos, 4); + if (w != 4) + perror("ERROR: write failed in writeidx"); + w = write(vfp, &tmp, 2); + if (w != 2) + perror("ERROR: write failed in writeidx"); } } } Index: debian/utilities/genbookutil.cpp =================================================================== --- debian.orig/utilities/genbookutil.cpp +++ debian/utilities/genbookutil.cpp @@ -53,9 +53,11 @@ void printLocalName(TreeKeyIdx *treeKey) void setLocalName(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Node Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in setLocalName\n"; SWBuf name = buf; treeKey->setLocalName(name.trim()); treeKey->save(); @@ -63,18 +65,22 @@ void setLocalName(TreeKeyIdx *treeKey) { void gotoPath(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter Path: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in gotoPath\n"; SWBuf path = buf; (*treeKey) = path.trim(); } void assurePath(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter Path: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in assurePath\n"; SWBuf path = buf; treeKey->assureKeyPath(path.trim()); } @@ -91,10 +97,12 @@ void setEntryText(RawGenBook *book) { SWBuf body; TreeKeyIdx *treeKey = (TreeKeyIdx *)(SWKey *)(*book); if (treeKey->getOffset()) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Entry Text ('.' on a line by itself to end): \n"; do { - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in setEntryText\n"; SWBuf text = buf; text.trim(); if ((text[0] == '.') && (text[1] == 0)) @@ -111,9 +119,11 @@ void setEntryText(RawGenBook *book) { void appendSibbling(TreeKeyIdx *treeKey) { if (treeKey->getOffset()) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Sibbling Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendSibbling\n"; SWBuf name = buf; treeKey->append(); treeKey->setLocalName(name.trim()); @@ -124,9 +134,11 @@ void appendSibbling(TreeKeyIdx *treeKey) void appendChild(TreeKeyIdx *treeKey) { - char buf[1023]; + char buf[1023], *c; std::cout << "Enter New Child Name: "; - fgets(buf, 1000, stdin); + c = fgets(buf, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in appendChild\n"; SWBuf name = buf; treeKey->appendChild(); treeKey->setLocalName(name.trim()); @@ -168,11 +180,13 @@ int main(int argc, char **argv) { treeKey = (TreeKeyIdx *)(SWKey *)(*book); SWBuf input; - char line[1024]; + char line[1024], *c; do { std::cout << "[" << treeKey->getText() << "] > "; - fgets(line, 1000, stdin); + c = fgets(line, 1000, stdin); + if (c == NULL) + std::cerr << "ERROR: fgets failed in main\n"; input = line; input.trim(); if (input.length() > 0) { Index: debian/utilities/vpl2mod.cpp =================================================================== --- debian.orig/utilities/vpl2mod.cpp +++ debian/utilities/vpl2mod.cpp @@ -72,14 +72,18 @@ char readline(int fd, char **buf) { break; } - int size = (lseek(fd, 0, SEEK_CUR) - index) - 1; + int r, size = (lseek(fd, 0, SEEK_CUR) - index) - 1; *buf = new char [ size + 1 ]; if (size > 0) { lseek(fd, index, SEEK_SET); - read(fd, *buf, size); - read(fd, &ch, 1); //pop terminating char + r = read(fd, *buf, size); + if (r != size) + std::cerr <<"ERROR: short read in readline\n"; + r = read(fd, &ch, 1); //pop terminating char + if (r != size) + std::cerr <<"ERROR: short read of terminating char in readline\n"; (*buf)[size] = 0; // clean up any trailing junk on buf Index: debian/utilities/installmgr.cpp =================================================================== --- debian.orig/utilities/installmgr.cpp +++ debian/utilities/installmgr.cpp @@ -69,8 +69,10 @@ virtual bool isUserDisclaimerConfirmed() cout << "then type yes at the prompt\n\n"; cout << "enable? [no] "; - char prompt[10]; - fgets(prompt, 9, stdin); + char prompt[10], *c; + c = fgets(prompt, 9, stdin); + if (c == NULL) + std::cerr <<"ERROR: fgets failed in isUserDisclaimerConfirmed\n"; confirmed = (!strcmp(prompt, "yes\n")); cout << "\n"; } Index: debian/utilities/step2vpl.cpp =================================================================== --- debian.orig/utilities/step2vpl.cpp +++ debian/utilities/step2vpl.cpp @@ -223,93 +223,169 @@ int main(int argc, char **argv) { void readVersion(int fd, Version *versionRecord) { + int r; - read(fd, &(versionRecord->versionRecordSize), 2); - read(fd, &(versionRecord->publisherID), 2); - read(fd, &(versionRecord->bookID), 2); - read(fd, &(versionRecord->setID), 2); - read(fd, &(versionRecord->conversionProgramVerMajor), 1); - read(fd, &(versionRecord->conversionProgramVerMinor), 1); - read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); - read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); - read(fd, &(versionRecord->encryptionType), 1); - read(fd, &(versionRecord->editionID), 1); - read(fd, &(versionRecord->modifiedBy), 2); + r = read(fd, &(versionRecord->versionRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + + r = read(fd, &(versionRecord->publisherID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->bookID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->setID), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->conversionProgramVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->conversionProgramVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->leastCompatSTEPVerMajor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->leastCompatSTEPVerMinor), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->encryptionType), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->editionID), 1); + if (r != 1) + perror("ERROR: read failed in readVersion"); + r = read(fd, &(versionRecord->modifiedBy), 2); + if (r != 2) + perror("ERROR: read failed in readVersion"); int skip = versionRecord->versionRecordSize - 16/*sizeof(struct Version*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readVersion"); delete [] skipbuf; } } void readSectionsHeader(int fd, SectionsHeader *sectionsHeaderRecord) { + int r; - read(fd, &(sectionsHeaderRecord->sectionsHeaderRecordSize), 2); - read(fd, &(sectionsHeaderRecord->levelEntriesCount), 4); - read(fd, &(sectionsHeaderRecord->glossEntriesCount), 4); - read(fd, &(sectionsHeaderRecord->levelEntriesSize), 2); - read(fd, &(sectionsHeaderRecord->reserved), 4); + r = read(fd, &(sectionsHeaderRecord->sectionsHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->levelEntriesCount), 4); + if (r != 4) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->glossEntriesCount), 4); + if (r != 4) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->levelEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readSectionsHeader"); + r = read(fd, &(sectionsHeaderRecord->reserved), 4); + if (r != 4) + perror("ERROR: read failed in readSectionsHeader"); int skip = sectionsHeaderRecord->sectionsHeaderRecordSize - 16/*sizeof(struct ViewableHeader)*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readSectionsHeader"); delete [] skipbuf; } } void readViewableHeader(int fd, ViewableHeader *viewableHeaderRecord) { + int r; - read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); - read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); - read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); - read(fd, &(viewableHeaderRecord->compressionType), 1); - read(fd, &(viewableHeaderRecord->reserved1), 1); - read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); - read(fd, &(viewableHeaderRecord->reserved2), 2); + r = read(fd, &(viewableHeaderRecord->viewableHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->viewableBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->glossBlocksCount), 4); + if (r != 4) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->compressionType), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->reserved1), 1); + if (r != 1) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->blockEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); + r = read(fd, &(viewableHeaderRecord->reserved2), 2); + if (r != 2) + perror("ERROR: read failed in readViewableHeader"); int skip = viewableHeaderRecord->viewableHeaderRecordSize - 16/*sizeof(struct ViewableHeader)*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readViewableHeader"); delete [] skipbuf; } } void readVSyncHeader(int fd, VSyncHeader *vSyncHeaderRecord) { + int r; - read(fd, &(vSyncHeaderRecord->vSyncHeaderRecordSize), 2); - read(fd, &(vSyncHeaderRecord->startBookNumber), 2); - read(fd, &(vSyncHeaderRecord->endBookNumber), 2); - read(fd, &(vSyncHeaderRecord->bookPointerEntriesSize), 2); - read(fd, &(vSyncHeaderRecord->syncPointEntriesSize), 2); - read(fd, &(vSyncHeaderRecord->reserved1_1), 4); - read(fd, &(vSyncHeaderRecord->reserved1_2), 2); + r = read(fd, &(vSyncHeaderRecord->vSyncHeaderRecordSize), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->startBookNumber), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->endBookNumber), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->bookPointerEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->syncPointEntriesSize), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->reserved1_1), 4); + if (r != 4) + perror("ERROR: read failed in readVSyncHeader"); + r = read(fd, &(vSyncHeaderRecord->reserved1_2), 2); + if (r != 2) + perror("ERROR: read failed in readVSyncHeader"); int skip = vSyncHeaderRecord->vSyncHeaderRecordSize - 16/*sizeof(VSyncHeader)*/; if (skip) { char *skipbuf = new char[skip]; - read(fd, skipbuf, skip); + r = read(fd, skipbuf, skip); + if (r != skip) + perror("ERROR: read failed in readVSyncHeader"); delete [] skipbuf; } } void readViewableBlockText(int fd, ViewableBlock *vb, char **buf) { + int r; unsigned long size = vb->size; *buf = new char [ ((vb->size > vb->uncompressedSize) ? vb->size : vb->uncompressedSize) + 1 ]; lseek(fd, vb->offset, SEEK_SET); - read(fd, *buf, vb->size); + r = read(fd, *buf, vb->size); + if (r != vb->size) + perror("ERROR: read failed in readViewableBlockText"); compress->zBuf(&size, *buf); strcpy(*buf, compress->Buf()); @@ -317,35 +393,53 @@ void readViewableBlockText(int fd, Viewa void readViewableBlock(int fd, ViewableBlock *vb) { + int r; - read(fd, &(vb->offset), 4); - read(fd, &(vb->uncompressedSize), 4); - read(fd, &(vb->size), 4); + r = read(fd, &(vb->offset), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); + r = read(fd, &(vb->uncompressedSize), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); + r = read(fd, &(vb->size), 4); + if (r != 4) + perror("ERROR: read failed in readViewableBlock"); } void readHeaderControlWordAreaText(int fd, char **buf) { + int r; long headerControlWordAreaSize; - read(fd, &headerControlWordAreaSize, 4); + r = read(fd, &headerControlWordAreaSize, 4); + if (r != 4) + perror("ERROR: read failed in readHeaderControlWordAreaText"); *buf = new char [headerControlWordAreaSize + 1]; - read(fd, *buf, headerControlWordAreaSize); + r = read(fd, *buf, headerControlWordAreaSize); + if (r != headerControlWordAreaSize) + perror("ERROR: read failed in readHeaderControlWordAreaText"); (*buf)[headerControlWordAreaSize] = 0; } void readVSyncBooksInfo(int fd, VSyncHeader *vSyncHeaderRecord, VSyncBooksInfo **vSyncBooksInfo) { + int r; int bookCount = vSyncHeaderRecord->endBookNumber - vSyncHeaderRecord->startBookNumber; *vSyncBooksInfo = new VSyncBooksInfo[bookCount]; for (int i = 0; i <= bookCount; i++) { - read(fd, &(*vSyncBooksInfo)[i].offset, 4); - read(fd, &(*vSyncBooksInfo)[i].count, 2); + r = read(fd, &(*vSyncBooksInfo)[i].offset, 4); + if (r != 4) + perror("ERROR: read failed in readVSyncBooksInfo"); + r = read(fd, &(*vSyncBooksInfo)[i].count, 2); + if (r != 2) + perror("ERROR: read failed in readVSyncBooksInfo"); } } void displayBook(int fdbook, int fdviewable, int fdvsync, int fdsections, VSyncBooksInfo *vSyncBooksInfo) { + int r; VSyncPoint vSyncPoint; lseek(fdvsync, vSyncBooksInfo->offset, SEEK_SET); @@ -356,9 +450,15 @@ void displayBook(int fdbook, int fdviewa char *sectionName; char *verseText; - read(fdvsync, &(vSyncPoint.chapter), 2); - read(fdvsync, &(vSyncPoint.verse), 2); - read(fdvsync, &(vSyncPoint.offset), 4); + r = read(fdvsync, &(vSyncPoint.chapter), 2); + if (r != 2) + perror("ERROR: read failed in displayBook"); + r = read(fdvsync, &(vSyncPoint.verse), 2); + if (r != 2) + perror("ERROR: read failed in displayBook"); + r = read(fdvsync, &(vSyncPoint.offset), 4); + if (r != 4) + perror("ERROR: read failed in displayBook"); vSyncPoint.offset = SECTIONSLEVELSTART + (vSyncPoint.offset * SECTIONSLEVELSIZE); lseek(fdsections, vSyncPoint.offset, SEEK_SET); readSectionLevelInfo(fdsections, §ionLevelInfo); @@ -413,26 +513,50 @@ void extractVerseText(int fdviewable, in void readSectionName(int fd, SectionLevelInfo *sli, char **name) { + int r; short size; lseek(fd, sli->nameOffset, SEEK_SET); - read(fd, &size, 2); + r = read(fd, &size, 2); + if (r != 2) + perror("ERROR: read failed in readSectionName"); *name = new char [ size + 1 ]; - read(fd, *name, size); + r = read(fd, *name, size); + if (r != size) + perror("ERROR: read failed in readSectionName"); (*name)[size] = 0; } void readSectionLevelInfo(int fd, SectionLevelInfo *sli) { + int r; - read(fd, &(sli->parentOffset), 4); - read(fd, &(sli->previousOffset), 4); - read(fd, &(sli->nextOffset), 4); - read(fd, &(sli->viewableOffset), 4); + r = read(fd, &(sli->parentOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->previousOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->nextOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->viewableOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); sli->viewableOffset = VIEWABLEBLOCKSTART + (VIEWABLEBLOCKSIZE * sli->viewableOffset); - read(fd, &(sli->startLevel), 2); - read(fd, &(sli->level), 1); - read(fd, &(sli->nameOffset), 4); - read(fd, &(sli->outSync_1), 4); - read(fd, &(sli->outSync_2), 2); + r = read(fd, &(sli->startLevel), 2); + if (r != 2) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->level), 1); + if (r != 1) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->nameOffset), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->outSync_1), 4); + if (r != 4) + perror("ERROR: read failed in readSectionLevelInfo"); + r = read(fd, &(sli->outSync_2), 2); + if (r != 2) + perror("ERROR: read failed in readSectionLevelInfo"); } void cleanBuf(char *buf) { Index: debian/utilities/cipherraw.cpp =================================================================== --- debian.orig/utilities/cipherraw.cpp +++ debian/utilities/cipherraw.cpp @@ -48,7 +48,7 @@ int main(int argc, char **argv) { SWCipher *zobj; VerseKey key; RawVerse *rawdrv; - int ofd[2], oxfd[2]; + int ofd[2], oxfd[2], w; long tmpoff = 0, offset, loffset = 0, lzoffset = 0; unsigned short size, lsize = 0, lzsize; char *tmpbuf; @@ -74,10 +74,18 @@ int main(int argc, char **argv) { delete [] tmpbuf; printf("\n"); - write(oxfd[0], &lzoffset, 4); - write(oxfd[0], &lzsize, 2); - write(oxfd[1], &lzoffset, 4); - write(oxfd[1], &lzsize, 2); + w = write(oxfd[0], &lzoffset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + w = write(oxfd[0], &lzsize, 2); + if (w < 0) + perror("ERROR: write failed in main"); + w = write(oxfd[1], &lzoffset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + w = write(oxfd[1], &lzsize, 2); + if (w < 0) + perror("ERROR: write failed in main"); key.AutoNormalize(0); key.Headings(1); @@ -89,8 +97,13 @@ int main(int argc, char **argv) { printf("using previous offset,size %d\n", size); offset = lseek(oxfd[key.Testament() - 1], 0, SEEK_CUR); printf("%ld %ld %d \n", offset, lzoffset, lzsize); - write(oxfd[key.Testament() - 1], &lzoffset, 4); - write(oxfd[key.Testament() - 1], &lzsize, 2); + w = write(oxfd[key.Testament() - 1], &lzoffset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + + w = write(oxfd[key.Testament() - 1], &lzsize, 2); + if (w < 0) + perror("ERROR: write failed in main"); } else { lsize = size; @@ -107,13 +120,23 @@ int main(int argc, char **argv) { offset = lseek(ofd[key.Testament() - 1], 0, SEEK_CUR); tmpoff = lseek(oxfd[key.Testament() - 1], 0, SEEK_CUR); printf("%s: (%ld) NEW offset: %ld; size: %d\n", (const char *)key, tmpoff, offset, size); - write(oxfd[key.Testament() - 1], &offset, 4); + w = write(oxfd[key.Testament() - 1], &offset, 4); + if (w < 0) + perror("ERROR: write failed in main"); + unsigned long ulSize = size; - if (size) - write(ofd[key.Testament() - 1], zobj->cipherBuf(&ulSize), size); + if (size) { + w = write(ofd[key.Testament() - 1], zobj->cipherBuf(&ulSize), size); + if (w < 0) + perror("ERROR: write failed in main"); + } + size = (unsigned int)ulSize; lzoffset = offset; - write(oxfd[key.Testament() - 1], &size, 2); + w = write(oxfd[key.Testament() - 1], &size, 2); + if (w < 0) + perror("ERROR: write failed in main"); + lzsize = size; } } Index: debian/utilities/lexdump.c =================================================================== --- debian.orig/utilities/lexdump.c +++ debian/utilities/lexdump.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { char *tmpbuf; - int idxfd, datfd; + int idxfd, datfd, r; long offset; unsigned int size; char datbuf[255]; @@ -59,11 +59,17 @@ int main(int argc, char **argv) { offset = atoi(argv[2]) * 6; lseek(idxfd, offset, SEEK_SET); - read(idxfd, &offset, 4); - read(idxfd, &size, 2); + r = read(idxfd, &offset, 4); + if (r != 4) + perror("ERROR: read failed in main"); + r = read(idxfd, &size, 2); + if (r != 2) + perror("ERROR: read failed in main"); printf("offset: %ld; size: %d\n", offset, size); lseek(datfd, offset, SEEK_SET); - read(datfd, datbuf, 40); + r = read(datfd, datbuf, 40); + if (r != 40) + perror("ERROR: read failed in main"); datbuf[40] = 0; printf("%s\n", datbuf); close(datfd); Index: debian/src/modules/swmodule.cpp =================================================================== --- debian.orig/src/modules/swmodule.cpp +++ debian/src/modules/swmodule.cpp @@ -536,7 +536,7 @@ ListKey &SWModule::search(const char *is } } listKey << *resultKey; - listKey.GetElement()->userData = (void *)((__u32)(h->score(i)*100)); + listKey.GetElement()->userData = (void *)((long)(h->score(i)*100)); } (*percent)(98, percentUserData); } Index: debian/tests/ciphertest.cpp =================================================================== --- debian.orig/tests/ciphertest.cpp +++ debian/tests/ciphertest.cpp @@ -30,7 +30,7 @@ int main(int argc, char **argv) { } - int encipher = atoi(argv[2]); + long encipher = atoi(argv[2]); SWFilter *filter = new CipherFilter(argv[1]);