---------------------
PatchSet 2938
Date: 2011/01/05 16:16:06
Author: maynardj
Branch: HEAD
Tag: (none)
Branches:
Log:
Add argument checking for numerical arguments
Members:
ChangeLog:1.1940->1.1941
utils/opcontrol:1.170->1.171
Index: oprofile/utils/opcontrol
diff -u oprofile/utils/opcontrol:1.170 oprofile/utils/opcontrol:1.171
--- oprofile/utils/opcontrol:1.170 Mon Nov 29 15:05:44 2010
+++ oprofile/utils/opcontrol Wed Jan 5 21:16:08 2011
@@ -49,6 +49,31 @@
fi
}
+# guess_number_base() checks if string is a valid octal(8), hexidecimal(16),
+# or decimal number(10). The value is returned in $?. Returns 0, if string
+# isn't a octal, hexidecimal, or decimal number.
+guess_number_base()
+{
+ if [[ "$1" =~ ^0[0-7]*$ ]] ; then
+ return 8;
+ elif [[ "$1" =~ ^0x[0-9a-fA-F]+$ ]] ; then
+ return 16;
+ elif [[ "$1" =~ ^[1-9][0-9]*$ ]] ; then
+ return 10;
+ else
+ return 0;
+ fi
+}
+
+# check value is a valid number
+error_if_not_number()
+{
+ guess_number_base $2
+ if test "$?" -eq 0 ; then
+ echo "Argument for $1, $2, is not a valid number." >&2
+ exit 1
+ fi
+}
# rm_device arguments $1=file_name
rm_device()
@@ -754,6 +779,7 @@
;;
--buffer-size)
error_if_empty $arg $val
+ error_if_not_number $arg $val
BUF_SIZE=$val
DO_SETUP=yes
;;
@@ -763,6 +789,7 @@
exit 1
fi
error_if_empty $arg $val
+ error_if_not_number $arg $val
BUF_WATERSHED=$val
DO_SETUP=yes
;;
@@ -772,6 +799,7 @@
exit 1
fi
error_if_empty $arg $val
+ error_if_not_number $arg $val
CPU_BUF_SIZE=$val
DO_SETUP=yes
;;
@@ -802,6 +830,7 @@
echo "Call-graph profiling unsupported on this kernel/hardware" >&2
exit 1
fi
+ error_if_not_number $arg $val
CALLGRAPH=$val
DO_SETUP=yes
;;