[PATCH] libtracefs: Enhance error checking when reading a number from trace file

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

 



Additional check is added to tracefs_instance_file_read_number() API to
handle the case when the trace file does not contain any number.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx>
---
 src/tracefs-instance.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index 97bbb00..b5f8298 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -316,13 +316,14 @@ int tracefs_instance_file_read_number(struct tracefs_instance *instance,
 	long long num;
 	int ret = -1;
 	int size = 0;
+	char *endptr;
 	char *str;
 
 	str = tracefs_instance_file_read(instance, file, &size);
 	if (size && str) {
 		errno = 0;
-		num = strtoll(str, NULL, 0);
-		if (errno == 0) {
+		num = strtoll(str, &endptr, 0);
+		if (errno == 0 && str != endptr) {
 			*res = num;
 			ret = 0;
 		}
-- 
2.29.2




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux