aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-src/src/main/snprintf.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-10 03:08:51 +0900
committernsfisis <nsfisis@gmail.com>2026-08-10 03:08:51 +0900
commit746e29c353679e28e18650816745bffca7303e97 (patch)
tree52c2a44512c24956c0b7d30f20ca9048f6ca0258 /crates/shirabe-php-src/src/main/snprintf.rs
parent264feb1093d587e5df457fac023852a0e578b22f (diff)
downloadphp-shirabe-746e29c353679e28e18650816745bffca7303e97.tar.gz
php-shirabe-746e29c353679e28e18650816745bffca7303e97.tar.zst
php-shirabe-746e29c353679e28e18650816745bffca7303e97.zip
fix(php-src): assert php_gcvt's unported arguments up front
php_gcvt only ports the ndigit < 0 (dtoa mode 0) path and hardcodes the '.'/'E' separators of its sole caller into the placement logic, but it accepted any argument and silently produced a wrong string for the rest. Assert the supported combination instead, and turn the mode 2 bail-out into unreachable! now that the assert rules it out. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-src/src/main/snprintf.rs')
-rw-r--r--crates/shirabe-php-src/src/main/snprintf.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/shirabe-php-src/src/main/snprintf.rs b/crates/shirabe-php-src/src/main/snprintf.rs
index f1411d6e..c0a3f23a 100644
--- a/crates/shirabe-php-src/src/main/snprintf.rs
+++ b/crates/shirabe-php-src/src/main/snprintf.rs
@@ -6,9 +6,13 @@
/// produces the same digit string as `zend_dtoa` in mode 0 (both compute the unique shortest
/// decimal that round-trips), so only the digit placement logic is ported here.
pub fn php_gcvt(value: f64, ndigit: i32, dec_point: char, exponent: char) -> String {
+ assert!(ndigit == -1);
+ assert!(dec_point == '.');
+ assert!(exponent == 'E');
+
let mode = if ndigit >= 0 { 2 } else { 0 };
if mode != 0 {
- todo!("php_gcvt is only ported for ndigit < 0 (serialize_precision=-1)");
+ unreachable!("php_gcvt is only ported for ndigit < 0 (serialize_precision=-1)");
}
let ndigit = 17i32;