php / php/php-src

sscanf(): Bad scan conversion character "."

Open
#12,126 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: standard Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

https://3v4l.org/I1AVe

<?php

$format = 'only %d - %.1f';
printf($format, 1, 2);
$str = sprintf($format, 1, 2);
sscanf($str, $format, $low, $max);

Resulted in this output:

only 1 - 2.0
Fatal error: Uncaught ValueError: Bad scan conversion character "." in /in/I1AVe:6
Stack trace:
#0 /in/I1AVe(6): sscanf('only 1 - 2.0', 'only %d - %.1f', NULL, NULL)
#1 {main}
  thrown in /in/I1AVe on line 6

But I expected this output instead:

  • no error, because shouldn't any format which is not marked as "not supported" in the docs work in both directions?
PHP Version

PHP 8.x

Operating System

No response

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

Start with the PHP reproducer and the sscanf() format-parsing entry point; compare its handling of %.1f with the documented printf()/sprintf() behavior. Done means the supported format behavior is resolved consistently and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.