From 179f35702ece13f4ab7fd1b331bef664834d8473 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 18 Mar 2019 18:38:47 +0100 Subject: Add _c versions of functions that otherwise return static buffers We have a habit of returning static buffers from some functions, particularly when generating some kind of string values. This is convenient in terms of memory management, but it comes at the expense of not being thread-safe, and not allowing for two calls of the related function within one printf() statement. Let's introduce _c suffix versions of those functions where the caller passes in a talloc context from which the output buffer shall be allocated. Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b --- src/sim/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/sim') diff --git a/src/sim/core.c b/src/sim/core.c index 998e836b..63b3000b 100644 --- a/src/sim/core.c +++ b/src/sim/core.c @@ -305,6 +305,14 @@ char *osim_print_sw(const struct osim_card_hdl *ch, uint16_t sw_in) return osim_print_sw_buf(sw_print_buf, sizeof(sw_print_buf), ch, sw_in); } +char *osim_print_sw_c(const void *ctx, const struct osim_card_hdl *ch, uint16_t sw_in) +{ + char *buf = talloc_size(ctx, 256); + if (!buf) + return NULL; + return osim_print_sw_buf(buf, 256, ch, sw_in); +} + const struct osim_card_sw *osim_find_sw(const struct osim_card_profile *cp, uint16_t sw_in) { -- cgit v1.2.3