Merge pull request #1104 from laanwj/2012_04_clang
authorJeff Garzik <jgarzik@exmulti.com>
Sun, 15 Apr 2012 18:39:15 +0000 (11:39 -0700)
committerJeff Garzik <jgarzik@exmulti.com>
Sun, 15 Apr 2012 18:39:15 +0000 (11:39 -0700)
Enable and fix most compilation warnings

src/base58.h
src/qt/bitcoin.cpp
src/qt/qrcodedialog.cpp
src/test/key_tests.cpp

index 755e34c..7fefbc5 100644 (file)
@@ -396,6 +396,16 @@ public:
         return fExpectTestNet == fTestNet && (vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1));
     }
 
+    bool SetString(const char* pszSecret)
+    {
+        return CBase58Data::SetString(pszSecret) && IsValid();
+    }
+
+    bool SetString(const std::string& strSecret)
+    {
+        return SetString(strSecret.c_str());
+    }
+
     CBitcoinSecret(const CSecret& vchSecret, bool fCompressed)
     {
         SetSecret(vchSecret, fCompressed);
index bfb49cb..463b2cf 100644 (file)
@@ -119,6 +119,15 @@ std::string _(const char* psz)
     return QCoreApplication::translate("bitcoin-core", psz).toStdString();
 }
 
+/* Handle runaway exceptions. Shows a message box with the problem and quits the program.
+ */
+static void handleRunawayException(std::exception *e)
+{
+    PrintExceptionContinue(e, "Runaway exception");
+    QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occured. Bitcoin can no longer continue safely and will quit.") + QString("\n\n") + QString::fromStdString(strMiscWarning));
+    exit(1);
+}
+
 #ifdef WIN32
 #define strncasecmp strnicmp
 #endif
@@ -284,9 +293,9 @@ int main(int argc, char *argv[])
             return 1;
         }
     } catch (std::exception& e) {
-        PrintException(&e, "Runaway exception");
+        handleRunawayException(&e);
     } catch (...) {
-        PrintException(NULL, "Runaway exception");
+        handleRunawayException(NULL);
     }
     return 0;
 }
index 9965f14..2a428fb 100644 (file)
@@ -41,6 +41,11 @@ void QRCodeDialog::genCode()
         ui->lblQRCode->setText("");
 
         QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
+        if (!code)
+        {
+            ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
+            return;
+        }
         myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
         myImage.fill(0xffffff);
         unsigned char *p = code->data;
index bc8759b..a6dab62 100644 (file)
@@ -14,6 +14,7 @@ static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtm
 static const string strSecret2 ("5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3");
 static const string strSecret1C("Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw");
 static const string strSecret2C("L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g");
+static const string strAddress1("1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF");
 
 #ifdef KEY_TESTS_DUMPINFO
 void dumpKeyInfo(uint256 privkey)
@@ -47,11 +48,12 @@ BOOST_AUTO_TEST_SUITE(key_tests)
 
 BOOST_AUTO_TEST_CASE(key_test1)
 {
-    CBitcoinSecret bsecret1, bsecret2, bsecret1C, bsecret2C;
-    bsecret1.SetString (strSecret1);
-    bsecret2.SetString (strSecret2);
-    bsecret1C.SetString(strSecret1C);
-    bsecret2C.SetString(strSecret2C);
+    CBitcoinSecret bsecret1, bsecret2, bsecret1C, bsecret2C, baddress1;
+    BOOST_CHECK( bsecret1.SetString (strSecret1));
+    BOOST_CHECK( bsecret2.SetString (strSecret2));
+    BOOST_CHECK( bsecret1C.SetString(strSecret1C));
+    BOOST_CHECK( bsecret2C.SetString(strSecret2C));
+    BOOST_CHECK(!baddress1.SetString(strAddress1));
 
     bool fCompressed;
     CSecret secret1  = bsecret1.GetSecret (fCompressed);