Usermode - Fixed incorrect use of vsnprintf
authorJohn Hodge (sonata) <[email protected]>
Thu, 28 Mar 2013 05:05:52 +0000 (13:05 +0800)
committerJohn Hodge (sonata) <[email protected]>
Thu, 28 Mar 2013 05:05:52 +0000 (13:05 +0800)
Usermode/Applications/irc_src/main.c
Usermode/Libraries/libnet.so_src/socket.c

index 3448dbd..4ca2415 100644 (file)
@@ -340,7 +340,7 @@ tMessage *Message_AppendF(tServer *Server, int Type, const char *Source, const c
        va_list args;\r
         int    len;\r
        va_start(args, Message);\r
-       len = vsnprintf(NULL, 1000, Message, args);\r
+       len = vsnprintf(NULL, 0, Message, args);\r
        {\r
                char    buf[len+1];\r
                vsnprintf(buf, len+1, Message, args);\r
@@ -602,6 +602,10 @@ void ParseServerLine(tServer *Server, char *Line)
                        }\r
                        \r
                        //printf("[%s] NOTICE %s: %s\n", Server->Name, ident, message);\r
+                       char *ident_bang = strchr(ident, '!');\r
+                       if( ident_bang ) {\r
+                               *ident_bang = '\0';\r
+                       }\r
                        Message_Append(Server, MSG_TYPE_NOTICE, ident, "", message);\r
                }\r
                else if( strcmp(cmd, "PRIVMSG") == 0 )\r
@@ -619,7 +623,10 @@ void ParseServerLine(tServer *Server, char *Line)
                        // TODO: Catch when the privmsg is addressed to the user\r
 \r
 //                     Cmd_PRIVMSG(Server, dest, ident, message);\r
-                       *strchr(ident, '!') = '\0';     // Hello SIGSEGV\r
+                       char *ident_bang = strchr(ident, '!');\r
+                       if( ident_bang ) {\r
+                               *ident_bang = '\0';\r
+                       }\r
                        Message_Append(Server, MSG_TYPE_STANDARD, ident, dest, message);\r
                }\r
                else if( strcmp(cmd, "JOIN" ) == 0 )\r
@@ -709,7 +716,7 @@ int writef(int FD, const char *Format, ...)
         int    len;\r
        \r
        va_start(args, Format);\r
-       len = vsnprintf(NULL, 1000, Format, args);\r
+       len = vsnprintf(NULL, 0, Format, args);\r
        va_end(args);\r
        \r
        {\r
index f5933f2..85f7e54 100644 (file)
@@ -22,17 +22,17 @@ int Net_OpenSocket(int AddrType, void *Addr, const char *Filename)
        
        if(Filename)
        {
-                int    len = snprintf(NULL, 100, "/Devices/ip/routes/@%i:%s/%s", AddrType, hexAddr, Filename);
+                int    len = snprintf(NULL, 0, "/Devices/ip/routes/@%i:%s/%s", AddrType, hexAddr, Filename);
                char    path[len+1];
-               snprintf(path, 100, "/Devices/ip/routes/@%i:%s/%s", AddrType, hexAddr, Filename);
+               snprintf(path, len+1, "/Devices/ip/routes/@%i:%s/%s", AddrType, hexAddr, Filename);
                _SysDebug("%s", path);
                return _SysOpen(path, OPENFLAG_READ|OPENFLAG_WRITE);
        }
        else
        {
-                int    len = snprintf(NULL, 100, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr);
+                int    len = snprintf(NULL, 0, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr);
                char    path[len+1];
-               snprintf(path, 100, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr);
+               snprintf(path, len+1, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr);
                return _SysOpen(path, OPENFLAG_READ);
        }
 }

UCC git Repository :: git.ucc.asn.au