libtracefs: Enhance error checking when reading a number from trace file
PATCH 1/1 libtracefs: Enhance error checking when reading a number from trace file
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) <[email protected]>
--- src/tracefs-instance.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
src/tracefs-instance.c +3 -2
@@ -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 ; }
Signature · 1 line
2.29.2