From 6808d2ac6c1b47ad691284152aa58c95a3983048 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 2 Feb 2023 19:46:17 +0100 Subject: Avoid passing NULL to memcpy --- server.c | 5 ++++- user.c | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server.c b/server.c index 3a09aa2..69c3678 100644 --- a/server.c +++ b/server.c @@ -994,7 +994,10 @@ WritePackArgValue(FILE *file, const argument_t *arg) fprintf(file, "\t\tmsgh_simple = FALSE;\n"); fprintf(file, "\t}\n\telse {\n\t"); } - fprintf(file, "\tmemcpy(OutP->%s, %s, ", + fprintf(file, "\tif (%s)\n", count->argVarName); + if (it->itIndefinite) + fprintf(file, "\t"); + fprintf(file, "\t\tmemcpy(OutP->%s, %s, ", arg->argMsgField, arg->argVarName); if (btype->itTypeSize > 1) fprintf(file, "%d * ", diff --git a/user.c b/user.c index a189e75..e951ee2 100644 --- a/user.c +++ b/user.c @@ -455,7 +455,7 @@ WritePackArgValue(FILE *file, const argument_t *arg) else WriteMsgError(file, arg->argRoutine, "MIG_ARRAY_TOO_LARGE"); - fprintf(file, "\t}\n\telse {\n"); + fprintf(file, "\t}\n\telse if (%s%s) {\n", countRef, count->argVarName); fprintf(file, "\t\tmemcpy(InP->%s, %s%s, ", arg->argMsgField, ref, arg->argVarName); @@ -968,7 +968,7 @@ WriteExtractArgValue(FILE *file, const argument_t *arg) fprintf(file, "%d * ", btype->itTypeSize/btype->itNumber); fprintf(file, "OutP->%s);\n", count->argMsgField); fprintf(file, "\t}\n"); - fprintf(file, "\telse {\n"); + fprintf(file, "\telse if (OutP->%s) {\n", count->argMsgField); fprintf(file, "\t memcpy(%s%s, OutP->%s, ", ref, arg->argVarName, arg->argMsgField); @@ -1001,7 +1001,8 @@ WriteExtractArgValue(FILE *file, const argument_t *arg) * fill user`s area as much as possible. Return the correct * number of elements. */ - fprintf(file, "\t\tmemcpy(%s%s, OutP->%s, ", ref, arg->argVarName, + fprintf(file, "\t\tif (%s%s)\n", countRef, count->argVarName); + fprintf(file, "\t\t\tmemcpy(%s%s, OutP->%s, ", ref, arg->argVarName, arg->argMsgField); if (btype->itTypeSize > 1) fprintf(file, "%d * ", btype->itTypeSize); @@ -1015,7 +1016,7 @@ WriteExtractArgValue(FILE *file, const argument_t *arg) fprintf(file, ";\n"); WriteMsgError(file,arg->argRoutine, "MIG_ARRAY_TOO_LARGE"); - fprintf(file, "\t}\n\telse {\n"); + fprintf(file, "\t}\n\telse if (OutP->%s) {\n", count->argMsgField); fprintf(file, "\t\tmemcpy(%s%s, OutP->%s, ", ref, arg->argVarName, arg->argMsgField); -- cgit v1.2.3