[glib: 1/2] Improve g_ascii_formatd docs and preconditions
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] Improve g_ascii_formatd docs and preconditions
- Date: Wed, 19 Jan 2022 00:14:56 +0000 (UTC)
commit 6749b343fefc199fa3a5d800c5baf59dc8a130c2
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jan 19 00:14:55 2022 +0000
Improve g_ascii_formatd docs and preconditions
glib/gstrfuncs.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
index e486251ab..07d0dcd5a 100644
--- a/glib/gstrfuncs.c
+++ b/glib/gstrfuncs.c
@@ -927,7 +927,7 @@ g_ascii_dtostr (gchar *buffer,
* @buffer: A buffer to place the resulting string in
* @buf_len: The length of the buffer.
* @format: The printf()-style format to use for the
- * code to use for converting.
+ * code to use for converting
* @d: The #gdouble to convert
*
* Converts a #gdouble to a string, using the '.' as
@@ -935,6 +935,9 @@ g_ascii_dtostr (gchar *buffer,
* a printf()-style format string. Allowed conversion
* specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'.
*
+ * The @format must just be a single format specifier
+ * starting with `%`, expecting a #gdouble argument.
+ *
* The returned buffer is guaranteed to be nul-terminated.
*
* If you just want to want to serialize the value into a
@@ -951,6 +954,10 @@ g_ascii_formatd (gchar *buffer,
#ifdef USE_XLOCALE
locale_t old_locale;
+ g_return_val_if_fail (buffer != NULL, NULL);
+ g_return_val_if_fail (format[0] == '%', NULL);
+ g_return_val_if_fail (strpbrk (format + 1, "'l%") == NULL, NULL);
+
old_locale = uselocale (get_C_locale ());
_g_snprintf (buffer, buf_len, format, d);
uselocale (old_locale);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]