Skip to content

Commit 3592498

Browse files
committed
S_hv_delete_common: Use new utf8_to_bytes_new_pv
1 parent c74c422 commit 3592498

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

hv.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,19 +1337,23 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
13371337

13381338
if (is_utf8 && !(k_flags & HVhek_KEYCANONICAL)) {
13391339
const char * const keysave = key;
1340-
key = (char*)bytes_from_utf8((U8*)key, &klen, &is_utf8);
1340+
U8 * free_me = NULL;
13411341

1342-
if (is_utf8)
1342+
if (! utf8_to_bytes_new_pv(&key, &klen, &free_me)) {
13431343
k_flags |= HVhek_UTF8;
1344-
else
1344+
}
1345+
else {
13451346
k_flags &= ~HVhek_UTF8;
1346-
if (key != keysave) {
1347-
if (k_flags & HVhek_FREEKEY) {
1348-
/* This shouldn't happen if our caller does what we expect,
1349-
but strictly the API allows it. */
1350-
Safefree(keysave);
1347+
is_utf8 = false;
1348+
1349+
if (free_me) {
1350+
if (k_flags & HVhek_FREEKEY) {
1351+
/* This shouldn't happen if our caller does what we expect,
1352+
but strictly the API allows it. */
1353+
Safefree(keysave);
1354+
}
1355+
k_flags |= HVhek_WASUTF8 | HVhek_FREEKEY;
13511356
}
1352-
k_flags |= HVhek_WASUTF8 | HVhek_FREEKEY;
13531357
}
13541358
}
13551359

0 commit comments

Comments
 (0)