Skip to content

Commit

Permalink
Merge pull request #493 from ZeroCM/gen-c-malloc
Browse files Browse the repository at this point in the history
Added two malloc safety checks to c types. Still not totally mem safe
  • Loading branch information
jbendes authored Sep 3, 2024
2 parents fc8fc4a + ced1ceb commit 356384f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gen/emit/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,"}");
Expand Down Expand Up @@ -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,");
Expand Down

0 comments on commit 356384f

Please sign in to comment.