From ced1cebf8dc53888418c0295a1a029b8997e9eb5 Mon Sep 17 00:00:00 2001 From: Jonathan Bendes Date: Tue, 3 Sep 2024 17:14:25 -0400 Subject: [PATCH] Added two malloc safety checks to c types. Still not totally mem safe --- gen/emit/EmitC.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gen/emit/EmitC.cpp b/gen/emit/EmitC.cpp index 190b58a8..409e69db 100644 --- a/gen/emit/EmitC.cpp +++ b/gen/emit/EmitC.cpp @@ -913,6 +913,7 @@ struct EmitSource : public Emit emit(0,"%s* %s_copy(const %s* p)", tn_, tn_, tn_); emit(0,"{"); emit(1, "%s* q = (%s*) malloc(sizeof(%s));", tn_, tn_, tn_); + emit(1, "if (!q) return NULL;"); emit(1, "__%s_clone_array(p, q, 1);", tn_); emit(1, "return q;"); emit(0,"}"); @@ -997,6 +998,7 @@ struct EmitSource : public Emit // table... emit(0, " %s_subscription_t* n = (%s_subscription_t*)", tn_, tn_); emit(0, " malloc(sizeof(%s_subscription_t));", tn_); + emit(0, " if (!n) return NULL;"); emit(0, " n->user_handler = f;"); emit(0, " n->userdata = userdata;"); emit(0, " n->z_sub = zcm_subscribe (zcm, channel,");