For PR1050:
authorReid Spencer <rspencer@reidspencer.com>
Fri, 15 Dec 2006 19:44:51 +0000 (19:44 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Fri, 15 Dec 2006 19:44:51 +0000 (19:44 +0000)
Convert asserts into error messages.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Archive/Archive.cpp
lib/Archive/ArchiveReader.cpp
lib/Archive/ArchiveWriter.cpp
lib/Bytecode/Archive/Archive.cpp
lib/Bytecode/Archive/ArchiveReader.cpp
lib/Bytecode/Archive/ArchiveWriter.cpp

index a661a4e992a449cdaa0edc9364b789f5fe911cd2..3bbc49dbe2a84a905e9ace3f05ddc3eb701357e7 100644 (file)
@@ -62,7 +62,12 @@ ArchiveMember::ArchiveMember(Archive* PAR)
 // different file, presumably as an update to the member. It also makes sure
 // the flags are reset correctly.
 bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
-  assert(newFile.exists() && "Can't replace with a non-existent file");
+  if (!newFile.exists()) {
+    if (ErrMsg) 
+      *ErrMsg = "Can not replace an archive member with a non-existent file";
+    return true;
+  }
+
   data = 0;
   path = newFile;
 
index e4769cac888a4573c08a688c6278ebb58bbb136d..82ff9edc8ae427b9688ab2409b24578e46a230bf 100644 (file)
@@ -68,7 +68,11 @@ Archive::parseSymbolTable(const void* data, unsigned size, std::string* error) {
 ArchiveMember*
 Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
 {
-  assert(At + sizeof(ArchiveMemberHeader) < End && "Not enough data");
+  if (At + sizeof(ArchiveMemberHeader) >= End) {
+    if (error)
+      *error = "Unexpected end of file";
+    return 0;
+  }
 
   // Cast archive member header
   ArchiveMemberHeader* Hdr = (ArchiveMemberHeader*)At;
@@ -498,7 +502,12 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
                                     std::set<ModuleProvider*>& result,
                                     std::string* error)
 {
-  assert(mapfile && base && "Can't findModulesDefiningSymbols on new archive");
+  if (!mapfile || !base) {
+    if (error)
+      *error = "Empty archive invalid for finding modules defining symbols";
+    return false;
+  }
+
   if (symTab.empty()) {
     // We don't have a symbol table, so we must build it now but lets also
     // make sure that we populate the modules table as we do this to ensure
index d07fe960b538f7077e6726570a02beda33a4bd22..9f4e797998c74c2c769a77614069905d21ab8578 100644 (file)
@@ -153,7 +153,11 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
 bool
 Archive::addFileBefore(const sys::Path& filePath, iterator where, 
                         std::string* ErrMsg) {
-  assert(filePath.exists() && "Can't add a non-existent file");
+  if (!filePath.exists()) {
+    if (ErrMsg)
+      *ErrMsg = "Can not add a non-existent file to archive";
+    return true;
+  }
 
   ArchiveMember* mbr = new ArchiveMember(this);
 
@@ -385,8 +389,11 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
 {
   // Make sure they haven't opened up the file, not loaded it,
   // but are now trying to write it which would wipe out the file.
-  assert(!(members.empty() && mapfile->size() > 8) &&
-         "Can't write an archive not opened for writing");
+  if (members.empty() && mapfile->size() > 8) {
+    if (ErrMsg)
+      *ErrMsg = "Can't write an archive not opened for writing";
+    return true;
+  }
 
   // Create a temporary file to store the archive in
   sys::Path TmpArchive = archPath;
index a661a4e992a449cdaa0edc9364b789f5fe911cd2..3bbc49dbe2a84a905e9ace3f05ddc3eb701357e7 100644 (file)
@@ -62,7 +62,12 @@ ArchiveMember::ArchiveMember(Archive* PAR)
 // different file, presumably as an update to the member. It also makes sure
 // the flags are reset correctly.
 bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
-  assert(newFile.exists() && "Can't replace with a non-existent file");
+  if (!newFile.exists()) {
+    if (ErrMsg) 
+      *ErrMsg = "Can not replace an archive member with a non-existent file";
+    return true;
+  }
+
   data = 0;
   path = newFile;
 
index e4769cac888a4573c08a688c6278ebb58bbb136d..82ff9edc8ae427b9688ab2409b24578e46a230bf 100644 (file)
@@ -68,7 +68,11 @@ Archive::parseSymbolTable(const void* data, unsigned size, std::string* error) {
 ArchiveMember*
 Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
 {
-  assert(At + sizeof(ArchiveMemberHeader) < End && "Not enough data");
+  if (At + sizeof(ArchiveMemberHeader) >= End) {
+    if (error)
+      *error = "Unexpected end of file";
+    return 0;
+  }
 
   // Cast archive member header
   ArchiveMemberHeader* Hdr = (ArchiveMemberHeader*)At;
@@ -498,7 +502,12 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
                                     std::set<ModuleProvider*>& result,
                                     std::string* error)
 {
-  assert(mapfile && base && "Can't findModulesDefiningSymbols on new archive");
+  if (!mapfile || !base) {
+    if (error)
+      *error = "Empty archive invalid for finding modules defining symbols";
+    return false;
+  }
+
   if (symTab.empty()) {
     // We don't have a symbol table, so we must build it now but lets also
     // make sure that we populate the modules table as we do this to ensure
index d07fe960b538f7077e6726570a02beda33a4bd22..9f4e797998c74c2c769a77614069905d21ab8578 100644 (file)
@@ -153,7 +153,11 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
 bool
 Archive::addFileBefore(const sys::Path& filePath, iterator where, 
                         std::string* ErrMsg) {
-  assert(filePath.exists() && "Can't add a non-existent file");
+  if (!filePath.exists()) {
+    if (ErrMsg)
+      *ErrMsg = "Can not add a non-existent file to archive";
+    return true;
+  }
 
   ArchiveMember* mbr = new ArchiveMember(this);
 
@@ -385,8 +389,11 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
 {
   // Make sure they haven't opened up the file, not loaded it,
   // but are now trying to write it which would wipe out the file.
-  assert(!(members.empty() && mapfile->size() > 8) &&
-         "Can't write an archive not opened for writing");
+  if (members.empty() && mapfile->size() > 8) {
+    if (ErrMsg)
+      *ErrMsg = "Can't write an archive not opened for writing";
+    return true;
+  }
 
   // Create a temporary file to store the archive in
   sys::Path TmpArchive = archPath;