From 67b0ab857a37f92f8c73656fae9a11838aa9db43 Mon Sep 17 00:00:00 2001 From: estkme <145633413+estkme@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:01:15 +0800 Subject: [PATCH] snprintf use stack memory --- interface/apdu/pcsc.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/interface/apdu/pcsc.c b/interface/apdu/pcsc.c index 47e795d..7ddc66d 100644 --- a/interface/apdu/pcsc.c +++ b/interface/apdu/pcsc.c @@ -379,8 +379,9 @@ static int pcsc_list_iter(int index, const char *reader, void *userdata) { cJSON *json = userdata; cJSON *jreader; + char index_str[16]; - char *index_str; + snprintf(index_str, sizeof(index_str), "%d", index); jreader = cJSON_CreateObject(); if (!jreader) @@ -388,21 +389,11 @@ static int pcsc_list_iter(int index, const char *reader, void *userdata) return -1; } - index_str = malloc(16); - if (!index_str) - { - return -1; - } - - snprintf(index_str, 16, "%d", index); - if (!cJSON_AddStringToObject(jreader, "env", index_str)) { return -1; } - free(index_str); - if (!cJSON_AddStringToObject(jreader, "name", reader)) { return -1;