From 7aed660ebd3d4c8e87aa6d0efc0c7eecee56e0c5 Mon Sep 17 00:00:00 2001 From: pradeeptakdas <37864641+pradeeptakdas@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:17:04 -0400 Subject: [PATCH] RDKBDEV-2827: check scanf() return values to avoid compiler warnings (#213) Reason for change: avoid compiler warnings Test Procedure: Sanity. Risks: None. Signed-off-by: Andre McCurdy Co-authored-by: Andre McCurdy Co-authored-by: Karunakaran A <48997923+karuna2git@users.noreply.github.com> --- sampleapps/consumer/rbusOpenTelemetry.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sampleapps/consumer/rbusOpenTelemetry.c b/sampleapps/consumer/rbusOpenTelemetry.c index e5bf0798..ac7d2a7e 100644 --- a/sampleapps/consumer/rbusOpenTelemetry.c +++ b/sampleapps/consumer/rbusOpenTelemetry.c @@ -57,17 +57,20 @@ int main(int argc, char *argv[]) void GetTraceContextFromUser(char *traceparent, char *tracestate) { char buff[256]; - snprintf(traceparent, RBUS_OPEN_TELEMETRY_DATA_MAX, "traceparent:%s", buff); + memset(buff, '\0', 256); - memset(traceparent, '\0', RBUS_OPEN_TELEMETRY_DATA_MAX); - memset(tracestate, '\0', RBUS_OPEN_TELEMETRY_DATA_MAX); printf("Enter traceparent:"); - scanf("%s", buff); - snprintf(traceparent, RBUS_OPEN_TELEMETRY_DATA_MAX, "traceparent:%s", buff); + if (scanf("%s", buff) == 1) + snprintf(traceparent, RBUS_OPEN_TELEMETRY_DATA_MAX, "traceparent:%s", buff); + else + memset(traceparent, '\0', RBUS_OPEN_TELEMETRY_DATA_MAX); + memset(buff, '\0', 256); printf("Enter tracestate:"); - scanf("%s", buff); - snprintf(tracestate, RBUS_OPEN_TELEMETRY_DATA_MAX, "tracestate:%s", buff); + if (scanf("%s", buff) == 1) + snprintf(tracestate, RBUS_OPEN_TELEMETRY_DATA_MAX, "tracestate:%s", buff); + else + memset(tracestate, '\0', RBUS_OPEN_TELEMETRY_DATA_MAX); } void run_client()