mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 00:00:14 +01:00
glib-aux,core: use nm_memdup_nul() and nm_memcpy()
This commit is contained in:
parent
5e36955f0b
commit
77ea230817
3 changed files with 9 additions and 13 deletions
|
|
@ -153,16 +153,16 @@ nm_supplicant_config_add_option_with_type(NMSupplicantConfig *self,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
opt = g_slice_new0(ConfigOption);
|
||||
opt->value = g_malloc(len + 1);
|
||||
memcpy(opt->value, value, len);
|
||||
opt->value[len] = '\0';
|
||||
|
||||
opt->len = len;
|
||||
opt->type = type;
|
||||
opt = g_slice_new(ConfigOption);
|
||||
*opt = (ConfigOption){
|
||||
.value = nm_memdup_nul(value, len),
|
||||
.len = len,
|
||||
.type = type,
|
||||
};
|
||||
|
||||
{
|
||||
char buf[255];
|
||||
|
||||
memset(&buf[0], 0, sizeof(buf));
|
||||
memcpy(&buf[0], opt->value, opt->len > 254 ? 254 : opt->len);
|
||||
nm_log_info(LOGD_SUPPLICANT,
|
||||
|
|
|
|||
|
|
@ -157,8 +157,7 @@ nm_ref_string_new_len(const char *cstr, gsize len)
|
|||
g_atomic_int_inc(&rstr->_ref_count);
|
||||
} else {
|
||||
rstr = g_malloc((G_STRUCT_OFFSET(NMRefString, str) + 1u) + len);
|
||||
if (len > 0)
|
||||
memcpy((char *) rstr->str, cstr, len);
|
||||
nm_memcpy((char *) rstr->str, cstr, len);
|
||||
((char *) rstr->str)[len] = '\0';
|
||||
*((gsize *) &rstr->len) = len;
|
||||
rstr->_ref_count = 1;
|
||||
|
|
|
|||
|
|
@ -530,10 +530,7 @@ nm_str_buf_finalize(NMStrBuf *strbuf, gsize *out_len)
|
|||
char *str = g_steal_pointer(&strbuf->_priv_str);
|
||||
char *result;
|
||||
|
||||
result = g_new(char, strbuf->_priv_len + 1u);
|
||||
memcpy(result, str, strbuf->_priv_len);
|
||||
result[strbuf->_priv_len] = '\0';
|
||||
|
||||
result = nm_memdup_nul(str, strbuf->_priv_len);
|
||||
if (strbuf->_priv_do_bzero_mem)
|
||||
nm_explicit_bzero(str, strbuf->_priv_len);
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue