@@ -148,37 +148,35 @@ public static RuntimeScalar sprintf(RuntimeScalar runtimeScalar, RuntimeList lis
148
148
}
149
149
// System.err.println("DEBUG sprintf: before MISSING check - valueArgIndex=" + valueArgIndex + ", list.size=" + list.size() + ", vectorFlag=" + spec.vectorFlag);
150
150
if (valueArgIndex >= list .size ()) {
151
- if (spec .conversionChar == 'n' ) {
152
- // %n is a no-op for now - just continue without throwing
153
- continue ;
154
- }
155
-
156
- // Different formats have different MISSING patterns
151
+ // Generate warning
152
+ WarnDie .warn (new RuntimeScalar ("Missing argument in sprintf" ), new RuntimeScalar ("" ));
153
+
154
+ // Append appropriate default value directly to result
157
155
if (spec .conversionChar == 'f' || spec .conversionChar == 'F' ) {
158
- // Check the specific format
159
- if (spec .raw .matches ("%.0f" )) {
160
- result .append ("0 MISSING" );
161
- } else if (spec .raw .matches (" %.0f" )) {
162
- result .append (" 0 MISSING" );
163
- } else if (spec .raw .matches ("%.2f" )) {
164
- result .append ("0.00 MISSING" );
156
+ if (spec .precision >= 0 ) {
157
+ result .append (String .format ("%." + spec .precision + "f" , 0.0 ));
165
158
} else {
166
- result .append (" MISSING " );
159
+ result .append ("0.000000 " ); // Default precision is 6
167
160
}
168
161
} else if (spec .conversionChar == 'g' || spec .conversionChar == 'G' ) {
169
- if (spec .raw .matches ("%.0g" )) {
170
- result .append ("0 MISSING" );
171
- } else if (spec .raw .matches (" %.0g" )) {
172
- result .append (" 0 MISSING" );
173
- } else if (spec .raw .matches ("%.2g" )) {
174
- result .append ("0 MISSING" );
162
+ if (spec .precision == 0 ) {
163
+ result .append ("0" );
175
164
} else {
176
- result .append (" MISSING " );
165
+ result .append ("0 " ); // %g removes trailing zeros
177
166
}
167
+ } else if (spec .conversionChar == 'd' || spec .conversionChar == 'i' ||
168
+ spec .conversionChar == 'u' || spec .conversionChar == 'o' ||
169
+ spec .conversionChar == 'x' || spec .conversionChar == 'X' ) {
170
+ result .append ("0" );
171
+ } else if (spec .conversionChar == 's' ) {
172
+ result .append ("" ); // Empty string for %s
173
+ } else if (spec .conversionChar == 'c' ) {
174
+ result .append ("\0 " ); // Null character for %c
178
175
} else {
179
- result .append (" MISSING " );
176
+ result .append ("" ); // Default empty
180
177
}
181
- continue ;
178
+
179
+ continue ; // Skip to next format specifier
182
180
}
183
181
184
182
RuntimeScalar value = (RuntimeScalar ) list .elements .get (valueArgIndex );
0 commit comments