Skip to content

Commit 34daed3

Browse files
authored
Use Memcpy allocation with error handling (Follow-up to PR vgvassilev#1714) (vgvassilev#1726)
1 parent 6842b90 commit 34daed3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

include/clad/Differentiator/Differentiator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,11 @@ T& back(
355355
"you pass clad.so to clang.");
356356
#endif
357357
size_t length = GetLength(code);
358-
char* temp = (char*)malloc(length + 1);
359-
m_Code = temp;
360-
while ((*temp++ = *code++))
361-
;
358+
m_Code = (char*)malloc(length + 1);
359+
if (m_Code)
360+
memcpy((void*)m_Code, code, length + 1);
361+
else
362+
fprintf(stderr, "Error: Failed to allocate memory for m_Code\n");
362363
}
363364

364365
constexpr CUDA_HOST_DEVICE CladFunction(CladFunctionType f,

0 commit comments

Comments
 (0)