Jim Meyering <jim(a)meyering.net> wrote:
Nice patch!
...
Here's a patch that removes that and fixes the two typos:
[and if you want to tighten up the xstr*-based parsing, this
means there's one fewer use to change]
Whoops. That patch was buggy.
This one actually passes the tests:
--- src/stats_linux.c.~1~ 2008-01-28 11:16:14.000000000 +0100
+++ src/stats_linux.c 2008-01-29 10:46:38.000000000 +0100
@@ -289,6 +289,7 @@
return -1;
}
if (path[3] != '\0') {
+ const char *p = NULL;
if (path[3] >= 'a' && path[3] <= 'z') {
disk = ((disk + 1) * 26) + (path[3] - 'a');
if (disk < 0 || disk > 255) {
@@ -298,23 +299,17 @@
return -1;
}
- if (path[4] != '\0') {
- if (xstrtol_i(path+4, NULL, 10, &part) < 0 ||
- part < 1 || part > 15) {
- statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
- "invalid path, partition numbers for sdN
must be in range 1 - 15",
- domid);
- return -1;
- }
- }
+ if (path[4] != '\0')
+ p = path + 4;
} else {
- if (xstrtol_i(path+3, NULL, 10, &part) < 0 ||
- part < 1 || part > 15) {
- statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
- "invalid path, partition numbers for sdN must be
in range 1 - 15",
- domid);
- return -1;
- }
+ p = path + 3;
+ }
+ if (p && (xstrtol_i(p, NULL, 10, &part) < 0 ||
+ part < 1 || part > 15)) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, partition numbers for sdN must be in
range 1 - 15",
+ domid);
+ return -1;
}
}
@@ -328,7 +323,7 @@
disk = (path[2] - 'a');
if (disk < 0 || disk > 19) {
statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
- "invalid path, device names must be in range sda -
sdp",
+ "invalid path, device names must be in range sda -
sdt",
domid);
return -1;
}
@@ -337,7 +332,7 @@
if (xstrtol_i(path+3, NULL, 10, &part) < 0 ||
part < 1 || part > 63) {
statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
- "invalid path, partition numbers for sdN must be in
range 1 - 15",
+ "invalid path, partition numbers for sdN must be in
range 1 - 63",
domid);
return -1;
}