Skip to content

Commit

Permalink
Perl__byte_dump_string(): Properly handle NULL input
Browse files Browse the repository at this point in the history
Instead of an assert, this returns (nil) and things can proceed.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent d7d161e commit 7bb85a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions embed.fnc
Expand Up @@ -727,8 +727,8 @@ p |OP * |build_infix_plugin \
|NN OP *lhs \
|NN OP *rhs \
|NN void *tokendata
EXp |char * |_byte_dump_string \
|NN const U8 * const start \
EXp |const char *|_byte_dump_string \
|NULLOK const U8 * const start \
|const STRLEN len \
|const bool format
Adp |int |bytes_cmp_utf8 |NN const U8 *b \
Expand Down
5 changes: 2 additions & 3 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion utf8.c
Expand Up @@ -935,7 +935,7 @@ Perl_is_utf8_FF_helper_(const U8 * const s0, const U8 * const e,
return (require_partial) ? 0 : UTF8_MAXBYTES;
}

char *
const char *
Perl__byte_dump_string(pTHX_ const U8 * const start, const STRLEN len, const bool format)
{
/* Returns a mortalized C string that is a displayable copy of the 'len'
Expand All @@ -945,6 +945,10 @@ Perl__byte_dump_string(pTHX_ const U8 * const start, const STRLEN len, const boo
* 1 ab (that is a space between two hex digit bytes)
*/

if (start == NULL) {
return "(nil)";
}

const STRLEN output_len = 4 * len + 1; /* 4 bytes per each input, plus a
trailing NUL */
const U8 * s = start;
Expand Down

0 comments on commit 7bb85a5

Please sign in to comment.