microsoft / microsoft/STL

`<format>`: Should we verify character arrays being null-terminated when creating `basic_format_arg`?

Open
#5,094 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement format
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

There're Preconditions specified in [format.arg]/5 for constructing a basic_format_arg:

Preconditions: If decay_t<T> is char_type* or const char_type*, static_cast<const char_type*>(v) points to a NTCTS ([defns.ntcts]).

And character arrays are decayed per [format.arg]/6.9:

otherwise, if decay_t<TD> is char_type* or const char_type*, initializes value with static_cast<const char_type*>(v);

It seems that we can check the content of the array (of known bound) in this internal factory function.

https://github.com/microsoft/STL/blob/44a276fdff3463f7e0ab547458850c16925cab06/stl/inc/__msvc_ranges_tuple_formatter.hpp#L277-L293

Should we verify that the array is null-terminated? Note that the checking is not O(1) but still seems cheap in formatting to me.

Contributor guide

Open the contributing guide

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

Read stl/inc/__msvc_ranges_tuple_formatter.hpp around lines 277-293 and compare the character-array handling with the cited format.arg preconditions. Determine whether checking known-bound arrays for null termination is required, and resolve what behavior and coverage would count as complete; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.