Zbigniew Jędrzejewski-Szmek
52abc9fe96
basic/stdio-util: introduce asprintf_safe
...
asprintf is nice to use, but the _documented_ error return convention is
unclear:
> If memory allocation wasn't possible, or some other error occurs,
> these functions will return -1, and the contents of strp are undefined.
What exactly "undefined" means is up for debate: if it was really
undefined, the caller wouldn't be able to meaningfully clean up, because
they wouldn't know if strp is a valid pointer. So far we interpreted
"undefined" — in some parts of the code base — as "either NULL or a
valid pointer that needs to be freed", and — in other parts of the
codebase — as "always NULL". I checked glibc and musl, and they both
uncoditionally set the output pointer to NULL on failure.
There is also no information _why_ asprintf failed. It could be an
allocation error or format string error. But we just don't have this
information.
Let's add a wrapper that either returns a good string or a NULL pointer.
Since there's just one failure result, we don't need a separate return
value and an output argument and can simplify callers.
2026-03-06 17:46:59 +01:00
..
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-03-06 17:46:59 +01:00
2026-03-06 17:46:59 +01:00
2026-01-27 19:20:30 +01:00
2026-03-03 23:56:05 +01:00
2025-05-25 10:06:07 +02:00
2026-02-19 15:05:14 +01:00
2025-10-25 18:50:32 +02:00
2025-10-25 18:50:32 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-10-22 10:10:24 +02:00
2025-10-22 10:10:24 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-02-23 10:43:00 +01:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-11-02 17:13:31 +09:00
2025-12-15 08:50:13 +09:00
2025-04-04 21:02:18 +09:00
2026-01-06 10:34:02 +01:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-10-23 23:46:49 +09:00
2025-10-23 23:46:49 +09:00
2025-07-11 18:33:43 +09:00
2025-11-12 14:17:44 +08:00
2025-10-24 01:52:59 +09:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-02-04 02:45:17 +09:00
2026-02-04 02:45:17 +09:00
2026-03-03 08:49:23 +01:00
2026-03-03 08:48:01 +01:00
2025-12-15 08:50:13 +09:00
2025-10-16 17:00:29 +02:00
2026-01-02 09:22:23 +01:00
2026-03-05 20:23:24 +01:00
2026-01-02 04:05:45 +09:00
2026-01-25 20:51:50 +01:00
2026-01-25 20:51:50 +01:00
2025-11-22 10:19:41 +01:00
2026-01-02 04:05:45 +09:00
2026-02-09 02:05:57 +01:00
2025-11-19 13:14:15 +01:00
2025-11-19 13:14:15 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-03-03 08:49:23 +01:00
2025-11-22 10:19:41 +01:00
2026-03-04 08:28:29 +01:00
2026-03-04 08:28:29 +01:00
2025-10-16 17:00:29 +02:00
2026-02-13 16:08:23 +09:00
2026-02-13 16:08:23 +09:00
2025-09-19 14:46:55 +02:00
2025-10-16 17:00:29 +02:00
2026-03-04 07:36:10 +09:00
2025-10-16 17:00:29 +02:00
2026-01-28 10:56:53 +09:00
2025-10-16 17:00:29 +02:00
2025-11-20 09:04:35 +09:00
2025-11-20 09:04:35 +09:00
2025-07-10 16:18:10 +02:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-03-03 08:48:01 +01:00
2026-03-03 08:48:01 +01:00
2025-12-15 08:50:13 +09:00
2025-11-02 21:14:35 +01:00
2026-02-24 23:08:52 +09:00
2025-09-19 14:46:55 +02:00
2026-01-02 09:22:59 +01:00
2025-05-25 10:06:07 +02:00
2025-09-19 16:46:07 +02:00
2025-11-22 10:19:41 +01:00
2026-01-19 13:33:27 +01:00
2026-01-19 13:33:27 +01:00
2025-09-17 19:40:17 +01:00
2025-10-16 17:00:29 +02:00
2025-07-11 13:05:42 +09:00
2025-07-11 13:05:42 +09:00
2025-07-11 18:33:43 +09:00
2026-02-24 12:58:09 +00:00
2026-02-05 14:14:39 +01:00
2026-02-05 14:14:39 +01:00
2025-12-15 08:50:13 +09:00
2025-10-16 17:00:29 +02:00
2025-11-25 17:15:30 +01:00
2025-11-25 17:15:30 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-11-26 19:02:31 +09:00
2025-10-16 17:00:29 +02:00
2025-11-26 19:02:31 +09:00
2025-11-26 19:02:31 +09:00
2026-03-03 22:18:26 +01:00
2025-11-26 19:02:31 +09:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-11-13 08:02:05 +09:00
2025-11-13 08:02:05 +09:00
2025-05-27 22:33:57 +09:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-06-04 22:06:52 +02:00
2025-10-16 17:00:29 +02:00
2025-05-07 22:04:46 +09:00
2025-10-16 17:00:29 +02:00
2025-10-19 10:01:46 +09:00
2025-10-19 10:01:46 +09:00
2025-10-16 17:00:29 +02:00
2025-07-11 13:05:46 +09:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-11-17 21:30:29 +09:00
2025-10-16 17:00:29 +02:00
2025-10-16 17:00:29 +02:00
2026-02-16 08:09:33 +09:00
2026-01-02 04:05:45 +09:00
2026-02-09 09:07:15 +01:00
2025-10-16 17:00:29 +02:00
2025-12-15 08:50:13 +09:00
2026-02-16 09:44:52 +01:00
2025-05-25 09:40:26 +02:00
2025-11-17 22:38:38 +09:00
2026-01-02 04:05:45 +09:00
2026-03-04 07:36:10 +09:00
2025-10-16 17:00:29 +02:00
2026-03-01 08:51:14 +01:00
2025-10-16 17:00:29 +02:00
2025-07-01 12:29:15 +09:00
2025-10-16 17:00:29 +02:00
2025-04-18 14:19:16 +02:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-22 10:06:07 +02:00
2026-02-18 00:47:25 +09:00
2025-10-16 17:00:29 +02:00
2026-03-06 17:46:59 +01:00
2025-07-13 12:41:14 +02:00
2025-07-13 12:41:14 +02:00
2026-01-21 08:35:31 +09:00
2025-11-02 17:13:31 +09:00
2026-03-03 08:49:23 +01:00
2026-02-05 14:14:40 +01:00
2025-01-16 02:26:56 +01:00
2026-02-17 17:52:20 +01:00
2026-02-17 17:52:20 +01:00
2025-05-25 10:06:07 +02:00
2025-11-26 19:02:31 +09:00
2025-07-26 05:00:02 +09:00
2025-10-16 17:00:29 +02:00
2025-05-22 21:10:15 +02:00
2026-01-25 20:51:50 +01:00
2026-01-02 04:05:45 +09:00
2026-02-03 21:43:17 +09:00
2026-02-03 21:43:17 +09:00
2026-03-06 02:39:39 +09:00
2026-03-06 02:39:39 +09:00
2025-11-24 12:45:06 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-02-05 16:18:35 +01:00
2025-10-19 10:01:46 +09:00
2026-03-02 15:25:53 +09:00
2025-12-20 21:41:01 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-12-15 08:50:13 +09:00
2025-11-26 19:02:31 +09:00
2026-03-01 13:18:19 +01:00
2026-02-17 17:52:20 +01:00
2025-12-15 08:50:13 +09:00
2025-11-26 19:02:31 +09:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-10-16 17:00:29 +02:00
2026-01-13 10:21:04 +09:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-12-15 08:50:13 +09:00
2025-11-22 10:19:41 +01:00
2025-10-16 17:00:29 +02:00
2026-01-19 03:06:30 +01:00
2025-12-21 07:04:42 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-12-15 08:50:13 +09:00
2026-01-02 04:05:45 +09:00
2026-01-02 04:05:45 +09:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-11-26 19:02:31 +09:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-12-21 19:21:08 +01:00
2026-01-02 04:05:45 +09:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-03-05 10:27:58 +01:00
2026-02-17 14:56:00 +09:00
2025-11-25 20:49:39 +01:00
2025-11-25 20:49:39 +01:00
2025-10-16 17:00:29 +02:00
2025-03-31 15:14:28 +02:00
2026-03-03 08:49:23 +01:00
2026-03-03 08:49:23 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2026-02-05 14:14:39 +01:00
2026-02-05 14:14:39 +01:00
2026-03-06 17:46:59 +01:00
2026-03-06 17:46:59 +01:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-07-05 22:26:23 +02:00
2026-01-02 09:22:23 +01:00
2026-02-14 21:49:24 +01:00
2025-11-25 20:49:39 +01:00
2026-03-01 08:51:14 +01:00
2026-03-01 08:51:14 +01:00
2025-10-25 19:31:06 +02:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-05-25 10:06:07 +02:00
2025-11-26 19:02:31 +09:00
2025-05-25 10:06:07 +02:00
2026-01-02 04:05:45 +09:00
2026-02-16 09:37:32 +01:00
2026-01-02 09:22:59 +01:00
2025-12-15 18:09:21 +09:00
2026-01-02 09:22:59 +01:00
2026-02-11 02:39:25 +01:00
2025-10-16 17:00:29 +02:00
2026-01-02 09:39:32 +01:00
2026-02-24 18:29:37 +01:00
2026-02-24 18:29:37 +01:00
2026-02-24 18:29:37 +01:00
2025-10-16 17:00:29 +02:00
2025-10-16 17:00:29 +02:00
2026-02-23 13:05:23 +00:00
2026-02-23 13:05:23 +00:00
2026-03-04 07:36:10 +09:00
2025-11-26 19:02:31 +09:00
2026-03-03 22:18:26 +01:00
2025-11-26 19:02:31 +09:00
2025-05-25 10:06:07 +02:00
2025-10-16 17:00:29 +02:00
2025-12-15 08:50:13 +09:00
2026-01-02 04:05:45 +09:00
2026-03-03 08:49:23 +01:00
2025-10-16 17:00:29 +02:00