From 678730d7b5502b940557251239cfef93e2baed2a Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 11 May 2023 13:28:33 +0200 Subject: [PATCH] MT#57408 warning: clearing an object of non-trivial type This commit fixes this: In file included from sip_parser_async.cpp:1: sip_parser_async.h: In member function 'void parser_state::reset_hdr_parser()': sip_parser_async.h:32:37: warning: 'void* memset(void*, int, size_t)' clearing an object of non-trivial type 'struct sip_header'; use assignment or value-initialization instead [-Wclass-memaccess] 32 | memset(&hdr,0,sizeof(sip_header)); | ^ In file included from sip_parser_async.h:4, from sip_parser_async.cpp:1: parse_header.h:44:8: note: 'struct sip_header' declared here 44 | struct sip_header | ^~~~~~~~~~ sip_parser_async.cpp: In function 'int parse_headers_async(parser_state*, char*)': sip_parser_async.cpp:215:36: warning: 'void* memset(void*, int, size_t)' clearing an object of non-trivial type 'struct sip_header'; use assignment or value-initialization instead [-Wclass-memaccess] 215 | memset(hdr,0,sizeof(sip_header)); | ^ In file included from sip_parser_async.h:4, from sip_parser_async.cpp:1: parse_header.h:44:8: note: 'struct sip_header' declared here 44 | struct sip_header | ^~~~~~~~~~ In general, using `var1 = {};` approach to initialize/clear a struct is equivalent to using `memset(var1, 0, sizeof(MyOwnStruct1));`. So there shouldn't be any big risks associated with swapping one for the other. The `memset()` may be slightly more efficient in terms of performance, especially when dealing with array of structures, but in this situation we are dealing with quite a small struct, which represents: a type, a name and a value. As long as `var1 = {};` approach is supported by our compiler and we don't need to initialize a large array of structures (in our case it isn't), there shouldn't be any big risks associated with swapping one for the other. Change-Id: I10570b628d3e5a634d764b83f7558d38ecc6a757 --- core/sip/sip_parser_async.cpp | 2 +- core/sip/sip_parser_async.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sip/sip_parser_async.cpp b/core/sip/sip_parser_async.cpp index 39384566..a2b76daa 100644 --- a/core/sip/sip_parser_async.cpp +++ b/core/sip/sip_parser_async.cpp @@ -212,7 +212,7 @@ int parse_headers_async(parser_state* pst, char* end) } // reset header struct - memset(hdr,0,sizeof(sip_header)); + hdr = {}; //memset(hdr, 0, sizeof(sip_header)); st = 0; saved_st = 0; pst->beg = c; diff --git a/core/sip/sip_parser_async.h b/core/sip/sip_parser_async.h index fb2c827c..a30effd4 100644 --- a/core/sip/sip_parser_async.h +++ b/core/sip/sip_parser_async.h @@ -29,7 +29,7 @@ struct parser_state } void reset_hdr_parser() { - memset(&hdr,0,sizeof(sip_header)); + hdr = {}; //memset(&hdr, 0, sizeof(sip_header)); st = saved_st = 0; beg = c; }