[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: |
Mike Frysinger |
Subject: |
Re: [gpsd-dev] [PATCH v1 1/1] gps2udp: atoi doesn't set errno. use strtoul to detect errors. |
Date: |
Fri, 3 Jan 2014 17:05:27 -0500 |
User-agent: |
KMail/1.13.7 (Linux/3.12.1; KDE/4.6.5; x86_64; ; ) |
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
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
signature.asc
Description: This is a digitally signed message part.