__GNUC__ || __clang__
| 233 | #pragma GCC diagnostic ignored "-Wformat-nonliteral" |
| 234 | #endif // __GNUC__ || __clang__ |
| 235 | static JSValue js_printf_internal(JSContext *ctx, |
| 236 | int argc, JSValueConst *argv, FILE *fp) |
| 237 | { |
| 238 | char fmtbuf[32]; |
| 239 | uint8_t cbuf[UTF8_CHAR_LEN_MAX+1]; |
| 240 | JSValue res; |
| 241 | DynBuf dbuf; |
| 242 | const char *fmt_str = NULL; |
| 243 | const uint8_t *fmt, *fmt_end; |
| 244 | const uint8_t *p; |
| 245 | char *q; |
| 246 | int i, c, len, mod; |
| 247 | size_t fmt_len; |
| 248 | int32_t int32_arg; |
| 249 | int64_t int64_arg; |
| 250 | double double_arg; |
| 251 | const char *string_arg; |
| 252 | |
| 253 | js_std_dbuf_init(ctx, &dbuf); |
| 254 | |
| 255 | if (argc > 0) { |
| 256 | fmt_str = JS_ToCStringLen(ctx, &fmt_len, argv[0]); |
| 257 | if (!fmt_str) |
| 258 | goto fail; |
| 259 | |
| 260 | i = 1; |
| 261 | fmt = (const uint8_t *)fmt_str; |
| 262 | fmt_end = fmt + fmt_len; |
| 263 | while (fmt < fmt_end) { |
| 264 | for (p = fmt; fmt < fmt_end && *fmt != '%'; fmt++) |
| 265 | continue; |
| 266 | dbuf_put(&dbuf, p, fmt - p); |
| 267 | if (fmt >= fmt_end) |
| 268 | break; |
| 269 | q = fmtbuf; |
| 270 | *q++ = *fmt++; /* copy '%' */ |
| 271 | |
| 272 | /* flags */ |
| 273 | for(;;) { |
| 274 | c = *fmt; |
| 275 | if (c == '0' || c == '#' || c == '+' || c == '-' || c == ' ' || |
| 276 | c == '\'') { |
| 277 | if (q >= fmtbuf + sizeof(fmtbuf) - 1) |
| 278 | goto invalid; |
| 279 | *q++ = c; |
| 280 | fmt++; |
| 281 | } else { |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | /* width */ |
| 286 | if (*fmt == '*') { |
| 287 | if (i >= argc) |
| 288 | goto missing; |
| 289 | if (JS_ToInt32(ctx, &int32_arg, argv[i++])) |
| 290 | goto fail; |
| 291 | q += snprintf(q, fmtbuf + sizeof(fmtbuf) - q, "%d", int32_arg); |
| 292 | fmt++; |
no test coverage detected