Skip to content

[Bug]: %% escape prints two percent signs when no format argument remains #379

Description

@leo-aa88

Description

The %% escape (a literal percent sign) is only collapsed to a single % when there is still an unconsumed format argument. When the format string has no remaining arguments — e.g. yapping("100%%"), or any %% that appears after all arguments have been consumed — both percent characters are emitted literally, so the output contains %% instead of %. This affects yapping, yappin, baka, and yapto (they share the formatter / the same code shape).

Minimal reproduction code

skibidi main {
    yapping("100%%");
    yapping("with arg %d and %%", 5);
    bussin 0;
}

Expected behavior

100%
with arg 5 and %

(As in C printf, %% always prints a single %.)

Actual behavior

$ ./brainrot pct.brainrot
100%%
with arg 5 and %%

Note the second line: after %d consumes the only argument, the trailing %% is also emitted literally.

Brainrot version / commit

19b9563

Operating system

Ubuntu on WSL2 (Linux 5.15)

Additional context

Root cause: stdrot/yapping.c (stdrot_format_to_stream) and identically stdrot/baka.c. The %% handling lives inside the branch guarded by if (*format == '%' && arg_idx < arg_count):

if (*format == '%' && arg_idx < arg_count)
{
    ...
    if (*format == '%') { buffer[buffer_offset++] = '%'; format++; continue; }
    ...
}
else
{
    buffer[buffer_offset++] = *format++;   // copies each '%' literally
}

When arg_idx >= arg_count, a % (including the first % of a %%) falls to the else branch and is copied verbatim, so %% survives as two characters. The %% escape should be recognized regardless of whether arguments remain — it consumes no argument.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions