All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] conf.c: parsing floating point numbers
@ 2002-07-02  8:52 Clemens Ladisch
  2002-07-03  9:23 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Clemens Ladisch @ 2002-07-02  8:52 UTC (permalink / raw)
  To: alsa-devel

When parse_value finds something looking like a number, it first calls
safe_strtoll to test whether the value's type is integer.
Unfortunately, safe_strtoll simply grabs anything which may be an
integer, and doesn't check for any following characters (e.g. the
decimal point of a floating point number).

This means that all floating point numbers are parsed as integers.

The patch adds a check for the end of the string, similar to
safe_strtol and safe_strtod.


--- alsa-lib/src/conf.c.org     Tue Jul  2 00:39:34 2002
+++ alsa-lib/src/conf.c Tue Jul  2 00:52:22 2002
@@ -463,11 +463,14 @@
 int safe_strtoll(const char *str, long long *val)
 {
        long long v;
+       int endidx;
        if (!*str)
                return -EINVAL;
        errno = 0;
-       if (sscanf(str, "%Ld", &v) != 1)
+       if (sscanf(str, "%Ld%n", &v, &endidx) < 1)
                return -EINVAL;
+       if (str[endidx])
+               return -EINVAL;
        *val = v;
        return 0;
 }


Clemens


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] conf.c: parsing floating point numbers
  2002-07-02  8:52 [PATCH] conf.c: parsing floating point numbers Clemens Ladisch
@ 2002-07-03  9:23 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2002-07-03  9:23 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

At Tue, 02 Jul 2002 10:52:03 +0200,
Clemens Ladisch wrote:
> 
> When parse_value finds something looking like a number, it first calls
> safe_strtoll to test whether the value's type is integer.
> Unfortunately, safe_strtoll simply grabs anything which may be an
> integer, and doesn't check for any following characters (e.g. the
> decimal point of a floating point number).
> 
> This means that all floating point numbers are parsed as integers.
> 
> The patch adds a check for the end of the string, similar to
> safe_strtol and safe_strtod.

thanks, applied to cvs.


Takashi


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
No, I will not fix your computer.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-03  9:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-02  8:52 [PATCH] conf.c: parsing floating point numbers Clemens Ladisch
2002-07-03  9:23 ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.