gnokii-users
[Top][All Lists]
Advanced

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

Re: more on smsreader


From: Nick Andrew
Subject: Re: more on smsreader
Date: Sun, 14 Apr 2002 20:35:48 +1000
User-agent: Mutt/1.3.27i

On Sun, Apr 14, 2002 at 11:24:59AM +0200, Bostjan Muller wrote:
> +  /* check if sender number is longer than 10 chars, and remove the first one
> +   * the + sign if it is */
> +  if ((num_len = strlen(message->RemoteNumber.number))>10) {
> +    if (message->RemoteNumber.number[0] == '+') {
> +      strncpy(number, message->RemoteNumber.number+1, num_len+1);
> +    }
> +  }

Surely this should be "num_len - 1" because you want to copy one less
byte than the length of the string.

Also, why does the "length > 10" test have to be in there? Surely if
you want to remove the '+' sign, just test if the first char is a +
and then remove it if so:

        char    *p = message->RemoteNumber.number;
        if (p->[0] == '+') {
                p++;
        }
        strcpy(number, p);

"strncpy" in your code gains nothing because the required data to copy
is always the source string until NUL. Introduction of the temporary
variable 'p' simplifies the arguments to strcpy and makes the intent
of the code more obvious: to copy everything except an optional leading
'+'.

Nick.
-- 



reply via email to

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