On Tue, Jan 03, 2017 at 11:47:50AM +0100, Pino Toscano wrote:
On Saturday, 24 December 2016 17:05:59 CET Richard W.M. Jones wrote:
--- python/Makefile.am | 5 ++++ src/appliance-kcmdline.c | 21 ++----------- src/drives.c | 65 +++++++---------------------------------- src/guestfs-internal-frontend.h | 3 ++ src/unit-tests.c | 40 +++++++++++++++++++++++++ src/utils.c | 50 +++++++++++++++++++++++++++++-- 6 files changed, 110 insertions(+), 74 deletions(-)
Look reasonable, just a couple of notes.
+bool +guestfs_int_string_is_valid (const char *str, + size_t min_length, size_t max_length, + bool alpha, bool digit, const char *extra)
min_length and max_length could be signed (ssize_t), with -1 (and even 0) indicating no actual limit. IMHO that could be slightly more readable than SIZE_MAX.
Also, all the usages so far pass alpha=true, so could be worth just assuming that for now, and dropping that parameter. After all, without alpha chars there are two combinations: a) a number b) number + extra chars (a) is already done by other functions converting string to numbers, while (b) looks like an uncommon case, and not needed yet.
I pushed this with a few changes suggested. min_length and max_length can be 0 to indicate no test. Instead of alpha/digit booleans, I used a flags field. However I left the alpha flag because otherwise it's not clear just by inspecting the code that alphabetic characters are permitted. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/