From 9dd0d3f550a0940dd53833666cd082e81aab8eff Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 29 Sep 2021 20:54:43 +0800 Subject: [PATCH] Don't memcpy to nullptr even if length is zero --- scene/main/http_request.cpp | 8 +++++--- servers/physics_3d/soft_body_3d_sw.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index f24d8800457..14fd14dd187 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -104,9 +104,11 @@ Error HTTPRequest::request(const String &p_url, const Vector &p_custom_h CharString charstr = p_request_data.utf8(); size_t len = charstr.length(); - raw_data.resize(len); - uint8_t *w = raw_data.ptrw(); - memcpy(w, charstr.ptr(), len); + if (len > 0) { + raw_data.resize(len); + uint8_t *w = raw_data.ptrw(); + memcpy(w, charstr.ptr(), len); + } return request_raw(p_url, p_custom_headers, p_ssl_validate_domain, p_method, raw_data); } diff --git a/servers/physics_3d/soft_body_3d_sw.cpp b/servers/physics_3d/soft_body_3d_sw.cpp index 5f6e202c73b..752d5f3a91d 100644 --- a/servers/physics_3d/soft_body_3d_sw.cpp +++ b/servers/physics_3d/soft_body_3d_sw.cpp @@ -249,8 +249,10 @@ void SoftBody3DSW::update_area() { // Node area. LocalVector counts; - counts.resize(nodes.size()); - memset(counts.ptr(), 0, counts.size() * sizeof(int)); + if (nodes.size() > 0) { + counts.resize(nodes.size()); + memset(counts.ptr(), 0, counts.size() * sizeof(int)); + } for (i = 0, ni = nodes.size(); i < ni; ++i) { nodes[i].area = 0.0;