linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Enhance error checking when reading a number from trace file
@ 2021-01-15  5:03 Tzvetomir Stoyanov (VMware)
  0 siblings, 0 replies; only message in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-01-15  5:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-15  5:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15  5:03 [PATCH] libtracefs: Enhance error checking when reading a number from trace file Tzvetomir Stoyanov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).