yaml / yaml/libyaml

`sprintf` is deprecated on MacOS if ASAN is enable.

Open Beginner friendly
#276 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1.2k
Forks
370
PR merge metrics
No merged PRs in 30d

Description

In dumper.c:

static yaml_char_t *
yaml_emitter_generate_anchor(SHIM(yaml_emitter_t *emitter), int anchor_id)
{
    yaml_char_t *anchor = YAML_MALLOC(ANCHOR_TEMPLATE_LENGTH);

    if (!anchor) return NULL;

    sprintf((char *)anchor, ANCHOR_TEMPLATE, anchor_id);

    return anchor;
}

You used sprintf. But when I enable ASAN and compile on Mac, I get this deprecation error:

/Users/richie/Documents/cxx_projects/iree.gd/thirdparty/iree/third_party/libyaml/src/dumper.c:254:5: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
    sprintf((char *)anchor, ANCHOR_TEMPLATE, anchor_id);
    ^

I have suppress the error on my project, but it sure does feel like beat around the bush instead of directly solve the problem though. Hopefully it can be replace with the safer variant, snprintf, and make compiling on MacOS with ASAN much easier.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dumper.c at yaml_emitter_generate_anchor and inspect ANCHOR_TEMPLATE_LENGTH alongside the existing formatting call. Build the project on macOS with ASAN enabled and confirm the deprecation warning is gone without changing the generated anchor text.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, macos
Domain
build-system
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.