qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [qemu-s390x] [PATCH v3 1/8] s390-ccw: update libc


From: Collin L. Walling
Subject: Re: [Qemu-devel] [qemu-s390x] [PATCH v3 1/8] s390-ccw: update libc
Date: Tue, 16 Jan 2018 12:19:38 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

On 01/16/2018 05:00 AM, Thomas Huth wrote:
On 15.01.2018 18:23, Collin L. Walling wrote:
On 01/15/2018 12:05 PM, Eric Blake wrote:
On 01/15/2018 10:44 AM, Collin L. Walling wrote:
[...]
+/**
+ * atoi:
+ * @str: the string to be converted.
+ *
+ * Given a string @str, convert it to an integer. Any non-numerical
value
+ * will terminate the conversion.
+ *
+ * Returns: an integer converted from the string @str.
+ */
+int atoi(const char *str)
+{
+    int i;
+    int val = 0;
+
+    for (i = 0; str[i]; i++) {
+        char c = str[i];
+        if (!isdigit(c)) {
+            break;
+        }
+        val *= 10;
+        val += c - '0';
Silently gives garbage on integer overflow, but matches the fact that
POSIX atoi() can't flag errors.  However, it does not handle leading
whitespace nor '-', which means it is NOT doing a POSIX-compatible
atoi() implementation; naming it atoi() is perhaps thus a disservice to
end users.
Fair enough. Perhaps the "strtoi" convention suits this better.
Or maybe simply add an assert(str[0] != '-') for now. If we ever hit the
assert, we can still add the support for negative numbers if necessary.


Eh... honestly it's easy enough to just add a flag for the negative sign
and handle it at the end.  We don't need it for this patch series, but at
least the support will be there. :)

[...]

--
- Collin L Walling




reply via email to

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