gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-dev] [PATCH v1 1/1] gps2udp: atoi doesn't set errno. use strto


From: Ferry Huberts
Subject: Re: [gpsd-dev] [PATCH v1 1/1] gps2udp: atoi doesn't set errno. use strtoul to detect errors.
Date: Fri, 03 Jan 2014 23:11:39 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0



On 03/01/14 23:05, Mike Frysinger wrote:
On Friday 03 January 2014 15:10:07 Ferry Huberts wrote:
+bool readUL(const char * str, unsigned long * dst) {
+       char * endPtr = NULL;

pretty sure style says to:
  - not cuddle the brace
  - not put a space after the *
  - not use camelCase


yes, sorry, I quickly copy/pasted that/my code from another project I'm involved in. Did not convert to gpsd style.

want me to resend of just go with what is now on master?

also, pretty sure there is no need to assign NULL to endPtr

-       portnum = atoi(portname);
-       if (errno != 0) {
+       bool validPort = readUL(portname, &portnum);
+       validPort = validPort && portnum > 0 && portnum < 65536;
+       if (!validPort) {

could do:
        bool validPort = readUL(portname, &portnum);
        if (!validPort || portnum == 0 || portnum >= 65536) {
                ...
-mike


--
Ferry Huberts



reply via email to

[Prev in Thread] Current Thread [Next in Thread]