Browse Source

fix build issues on newer compilers

Juanjo GutiÃerrez 1 year ago
parent
commit
ad0a63e275
6 changed files with 20 additions and 15 deletions
  1. 1 1
      src/Database.cpp
  2. 1 1
      src/Makefile.am
  3. 10 9
      src/Socket.cpp
  4. 1 0
      src/UnixLogger.cpp
  5. 2 1
      src/Utils.cpp
  6. 5 3
      src/hermes.cpp

+ 1 - 1
src/Database.cpp

@@ -392,7 +392,7 @@ unsigned long Database::getIntValue(string& p_sql)
 
   if(NULL==result)
     throw SQLException("SQL: "+p_sql+" didn't return any data, SQL query may be wrong",__FILE__,__LINE__);
-  if('\0'==result[ncolumn])
+  if('\0'==result[ncolumn][0])
     value=0; //why sqlite doesn't return 0 when there are no rows?
   else
     value=strtoul(result[ncolumn],NULL,10);

+ 1 - 1
src/Makefile.am

@@ -1,6 +1,6 @@
 INCLUDES = $(OpenSSL_CFLAGS) $(SQLite3_CFLAGS)
 LIBS = $(OpenSSL_LIBS) $(SQLite3_LIBS)
-CXXFLAGS += -Wall -ansi -pedantic -Wshadow -pthread
+CXXFLAGS += -Wall -ansi -pedantic -Wshadow -pthread -Werror --std=c++11
 
 bin_PROGRAMS = hermes
 nodist_hermes_SOURCES = Configfile.cpp

+ 10 - 9
src/Socket.cpp

@@ -19,6 +19,7 @@
  */
 #include "Socket.h"
 #include <unistd.h>
+#include <cstring>
 
 int Socket::created_sockets=0;
 
@@ -309,6 +310,10 @@ string Socket::readLine()
 {
   char c=0;
   stringstream s;
+  string ssl_debug_string="";
+  #ifdef HAVE_SSL
+  if (ssl_enabled) ssl_debug_string = "s";
+  #endif //HAVE_SSL
 
   do
   {
@@ -319,11 +324,7 @@ string Socket::readLine()
   }
   while(c!=10&&!isClosed());
 
-  LDEB(string("r") +
-  #ifdef HAVE_SSL
-    string(ssl_enabled?"s":"") +
-  #endif //HAVE_SSL
-  ">" + s.str());
+  LDEB(string("r") + ssl_debug_string + ">" + s.str());
 
   return s.str();
 }
@@ -372,12 +373,12 @@ void Socket::writeByte(char c)
 
 void Socket::writeLine(string s)
 {
-
-  LDEB(string("w") +
+  string ssl_debug_string="";
   #ifdef HAVE_SSL
-  string(ssl_enabled?"s":"") +
+  if (ssl_enabled) ssl_debug_string = "s";
   #endif //HAVE_SSL
-  ">" + s);
+
+  LDEB(string("w") + ssl_debug_string + ">" + s);
   s+="\r\n";
 
   writeBytes((void *)s.c_str(),s.length());

+ 1 - 0
src/UnixLogger.cpp

@@ -39,6 +39,7 @@ void UnixLogger::addMessage(string file,int line,int loglevel,string logmessage)
 
   if(loglevel<=cfg.getLogLevel())
   {
+    sloglevel = LOG_INFO;
     switch(loglevel)
     {
       case HERMES_LOG_INFO: sloglevel=LOG_INFO;break;

+ 2 - 1
src/Utils.cpp

@@ -20,6 +20,7 @@
 #include "Utils.h"
 
 #include <unistd.h>
+#include <cstring>
 
 extern Configfile cfg;
 extern LOGGER_CLASS hermes_log;
@@ -617,7 +618,7 @@ string Utils::gethostname()
   if('\0'==buf[0])
   {
     if(cfg.getHostname()!="")
-      strncpy(buf,cfg.getHostname().c_str(),HOST_NAME_MAX);
+      strncpy(buf,cfg.getHostname().c_str(),HOST_NAME_MAX - 1);
     else
     {
       if(-1==::gethostname(buf,HOST_NAME_MAX))

+ 5 - 3
src/hermes.cpp

@@ -17,6 +17,8 @@
  *
  * @author Juan José Gutiérrez de Quevedo <juanjo@gutierrezdequevedo.com>
  */
+#include "config.h"
+
 #include <iostream>
 #include <list>
 #include <stack>
@@ -63,12 +65,12 @@ __thread unsigned long connection_id;
 list<unsigned long> children;
 
 #ifdef HAVE_SSL
-pthread_mutex_t ssl_locks[CRYPTO_NUM_LOCKS]={PTHREAD_MUTEX_INITIALIZER};
+pthread_mutex_t ssl_locks[CRYPTO_num_locks()]={PTHREAD_MUTEX_INITIALIZER};
 
 void ssl_locking_function(int mode,int n,const char *file,int line)
 {
-  if(n>CRYPTO_NUM_LOCKS)
-    throw Exception(_("Error, "+Utils::inttostr(n)+" is bigger than CRYPTO_NUM_LOCKS("+Utils::inttostr(CRYPTO_NUM_LOCKS)+")"),__FILE__,__LINE__);
+  if(n>CRYPTO_num_locks())
+    throw Exception(_("Error, "+Utils::inttostr(n)+" is bigger than CRYPTO_num_locks()("+Utils::inttostr(CRYPTO_num_locks())+")"),__FILE__,__LINE__);
   if(mode&CRYPTO_LOCK)
     pthread_mutex_lock(&ssl_locks[n]);
   else