Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/notes/bugfix-22868.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ensure format() function recognizes a negative format length
19 changes: 17 additions & 2 deletions engine/src/exec-strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,18 @@ void MCStringsEvalFormat(MCExecContext& ctxt, MCStringRef p_format, MCValueRef*
bool t_zero_pad;
t_zero_pad = false;

bool t_is_negative = false;
*dptr++ = *t_native_format++;
while (*t_native_format == '-' || *t_native_format == '#' || *t_native_format == '0'
|| *t_native_format == ' ' || *t_native_format == '+')
{
// AL-2014-11-19: [[ Bug 14059 ]] Record position of last zero.
if (*t_native_format == '0')
prefix_zero = t_native_format;

if (*t_native_format == '-')
t_is_negative = true;

*dptr++ = *t_native_format++;
}
if (isdigit((uint1)*t_native_format))
Expand Down Expand Up @@ -1227,9 +1232,19 @@ void MCStringsEvalFormat(MCExecContext& ctxt, MCStringRef p_format, MCValueRef*
{
// AL-2014-11-19: [[ Bug 14059 ]] Pad with zeroes if the appropriate specifier flag was used
if (t_zero_pad)
t_success = MCStringAppendFormat(*t_result, "%0*s%@", width - t_range . length, "", *t_string);
{
if (!t_is_negative)
t_success = MCStringAppendFormat(*t_result, "%0*s%@", width - t_range . length, "", *t_string);
else
t_success = MCStringAppendFormat(*t_result, "%@", *t_string);
}
else
t_success = MCStringAppendFormat(*t_result, "%*s%@", width - t_range . length, "", *t_string);
{
if (!t_is_negative)
t_success = MCStringAppendFormat(*t_result, "%*s%@", width - t_range . length, "", *t_string);
else
t_success = MCStringAppendFormat(*t_result, "%@%*s", *t_string, width - t_range . length, "");
}
}
else
t_success = MCStringAppendFormat(*t_result, "%@", *t_string);
Expand Down