Sfoglia il codice sorgente

Merge pull request #462 from acplt/remove_atoi_tcp

using strtoul instead of atoi in networklayer_tcp
Julius Pfrommer 9 anni fa
parent
commit
749064e192
1 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 9 1
      examples/networklayer_tcp.c

+ 9 - 1
examples/networklayer_tcp.c

@@ -498,7 +498,15 @@ ClientNetworkLayerTCP_connect(UA_ConnectionConfig localConf, char *endpointUrl,
     UA_UInt16 port;
     for(port = 0; portpos < urlLength-1; portpos++) {
         if(endpointUrl[portpos] == ':') {
-            port = atoi(&endpointUrl[portpos+1]);
+            char *endPtr = NULL;
+            unsigned long int tempulong = strtoul(&endpointUrl[portpos+1], &endPtr, 10);
+            if (ERANGE != errno &&
+                tempulong < UINT16_MAX &&
+                tempulong > 0 &&
+                endPtr != &endpointUrl[portpos+1])
+            {
+                port = (UA_UInt16)tempulong;
+            }
             break;
         }
     }