# HG changeset patch # User unc0rr # Date 1353611941 -14400 # Node ID 6c5b4e69f03dd155f9844724ced02dcdc5b0ba2e # Parent 08960209db8c0fca3bf7b771d2526163595e6521 Fix some frontlib bugs diff -r 08960209db8c -r 6c5b4e69f03d QTfrontend/net/hwmap.cpp --- a/QTfrontend/net/hwmap.cpp Thu Nov 22 01:19:16 2012 +0400 +++ b/QTfrontend/net/hwmap.cpp Thu Nov 22 23:19:01 2012 +0400 @@ -48,7 +48,7 @@ case MAPGEN_REGULAR: m_map = flib_map_create_regular( seed.toUtf8().constData() - , "" // theme? here? + , "" , filter); break; case MAPGEN_MAZE: m_map = @@ -68,7 +68,7 @@ default: Q_ASSERT_X(false, "HWMap::getImage", "Unknown generator"); } - + qDebug(m_map->seed); start(true); } diff -r 08960209db8c -r 6c5b4e69f03d project_files/frontlib/socket.c --- a/project_files/frontlib/socket.c Thu Nov 22 01:19:16 2012 +0400 +++ b/project_files/frontlib/socket.c Thu Nov 22 23:19:01 2012 +0400 @@ -61,7 +61,7 @@ return result; } -TCPsocket listen(uint16_t port) { +TCPsocket flib_listen(uint16_t port) { IPaddress addr; addr.host = INADDR_ANY; SDLNet_Write16(port, &addr.port); @@ -77,7 +77,7 @@ if(result) { if(port > 0) { result->port = port; - result->sock = listen(result->port); + result->sock = flib_listen(result->port); } else { /* SDL_net does not seem to have a way to listen on a random unused port and find out which port that is, so let's try to find one ourselves. */ @@ -85,7 +85,7 @@ for(int i=0; !result->sock && i<1000; i++) { // IANA suggests using ports in the range 49152-65535 for things like this result->port = 49152+(rand()%(65536-49152)); - result->sock = listen(result->port); + result->sock = flib_listen(result->port); } } if(!result->sock) { diff -r 08960209db8c -r 6c5b4e69f03d project_files/frontlib/util/util.c --- a/project_files/frontlib/util/util.c Thu Nov 22 01:19:16 2012 +0400 +++ b/project_files/frontlib/util/util.c Thu Nov 22 23:19:01 2012 +0400 @@ -37,12 +37,18 @@ } char *flib_vasprintf(const char *fmt, va_list args) { - char *result = NULL; + char *result = NULL; if(!log_badargs_if(fmt==NULL)) { - int requiredSize = vsnprintf(NULL, 0, fmt, args)+1; // Figure out how much memory we need, - if(!log_e_if(requiredSize<0, "Error formatting string with template \"%s\"", fmt)) { + va_list args_copy; + va_copy(args_copy, args); + + int requiredSize = vsnprintf(NULL, 0, fmt, args_copy)+1; // Figure out how much memory we need, + + va_end(args_copy); + + if(!log_e_if(requiredSize<0, "Error formatting string with template \"%s\"", fmt)) { char *tmpbuf = flib_malloc(requiredSize); // allocate it - if(tmpbuf && vsnprintf(tmpbuf, requiredSize, fmt, args)>=0) { // and then do the actual formatting. + if(tmpbuf && vsnprintf(tmpbuf, requiredSize, fmt, args)>=0) { // and then do the actual formatting. result = tmpbuf; tmpbuf = NULL; }