all/trivial: add code comment about using alloca() inside a loop

lgtm.com warns about these uses. They are correct though. Maybe the code should
not use alloca() simply to suppress the warning. Instead, add a comment pointing
out that this is in fact correct.
This commit is contained in:
Thomas Haller 2021-05-27 09:09:29 +02:00
parent f903d3b7b8
commit d5e8d1382b
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 5 additions and 3 deletions

View file

@ -1863,10 +1863,11 @@ clear_secrets(const NMSettInfoSetting * sett_info,
gs_free char *name_free = NULL;
const char * name;
/* only stack-allocate (alloca) a few times. */
if (j++ < 5)
if (j++ < 5) {
/* we use alloca() inside a loop here, but it is guarded to happen at most
* a few times. */
name = peers_psk_get_secret_name_a(peer->public_key, &name_free);
else {
} else {
name_free = peers_psk_get_secret_name_dup(peer->public_key);
name = name_free;
}

View file

@ -121,6 +121,7 @@ _value_str_as_index_list(const char *value, gsize *out_len)
str += good;
} else {
if (!str_cloned) {
/* we use alloca() inside a loop here, but it is guarded to happen at most once. */
str_cloned = TRUE;
str = nm_strndup_a(200, str, strlen(str), &str_clone_free);
}