From: Maxim Mamontov <faust.madf@gmail.com>
Date: Thu, 1 Sep 2011 10:57:52 +0000 (+0300)
Subject: Add assertions on OpenSearch results
X-Git-Tag: 2.408-alpha~9
X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/cf951863b80fb594f99b29e87558e03d453f75ef?ds=sidebyside

Add assertions on OpenSearch results
---

diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp
index 004210d2..bdbfe3a9 100644
--- a/projects/stargazer/plugins/authorization/ao/ao.cpp
+++ b/projects/stargazer/plugins/authorization/ao/ao.cpp
@@ -27,6 +27,7 @@ $Author: faust $
 #include <unistd.h>
 
 #include <csignal>
+#include <cassert>
 #include <algorithm> // for_each
 #include <functional> // mem_fun_ref
 
@@ -200,11 +201,7 @@ void AUTH_AO::GetUsers()
 {
 USER_PTR u;
 int h = users->OpenSearch();
-if (!h)
-    {
-    printfd(__FILE__, "users->OpenSearch() error\n");
-    return;
-    }
+assert(h && "USERS::OpenSearch is always correct");
 
 while (!users->SearchNext(h, &u))
     {
diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp
index 7abc53b9..2968082a 100644
--- a/projects/stargazer/plugins/other/ping/ping.cpp
+++ b/projects/stargazer/plugins/other/ping/ping.cpp
@@ -1,6 +1,6 @@
-#include <stdio.h>
-#include <signal.h>
-
+#include <cstdio>
+#include <cassert>
+#include <csignal>
 #include <ctime>
 #include <algorithm>
 
@@ -296,11 +296,7 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
 USER_PTR u;
 int h = users->OpenSearch();
-if (!h)
-    {
-    printfd(__FILE__, "users->OpenSearch() error\n");
-    return;
-    }
+assert(h && "USERS::OpenSearch is always correct");
 
 while (users->SearchNext(h, &u) == 0)
     {
diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp
index 237799f5..ff18a5e2 100644
--- a/projects/stargazer/traffcounter_impl.cpp
+++ b/projects/stargazer/traffcounter_impl.cpp
@@ -100,13 +100,8 @@ if (ReadRules())
 
 printfd(__FILE__, "TRAFFCOUNTER::Start()\n");
 int h = users->OpenSearch();
+assert(h && "USERS::OpenSearch is always correct");
 USER_IMPL * u;
-if (!h)
-    {
-    printfd(__FILE__, "TRAFFCOUNTER_IMPL::Start() - Cannot get users\n");
-    WriteServLog("TRAFFCOUNTER: Cannot get users.");
-    return -1;
-    }
 
 while (users->SearchNext(h, &u) == 0)
     {
@@ -132,11 +127,7 @@ if (stopped)
 running = false;
 
 int h = users->OpenSearch();
-if (!h)
-    {
-    WriteServLog("TRAFFCOUNTER: Fatal error: Cannot get users.");
-    return -1;
-    }
+assert(h && "USERS::OpenSearch is always correct");
 
 USER_IMPL * u;
 while (users->SearchNext(h, &u) == 0)