[libgda/LIBGDA_4.2] Improved code readability, and correction for bug #597390



commit 35ac120f31113106d5345e76826444dd6ae7580e
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Nov 1 17:01:50 2011 +0100

    Improved code readability, and correction for bug #597390

 libgda/gda-value.c |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/libgda/gda-value.c b/libgda/gda-value.c
index 6ce9fb2..9774ed9 100644
--- a/libgda/gda-value.c
+++ b/libgda/gda-value.c
@@ -2676,7 +2676,8 @@ gda_ushort_get_type (void) {
  *
  * Converts all the non printable characters of bin->data into the "\xyz" representation
  * where "xyz" is the octal representation of the byte, and the '\' (backslash) character
- * is converted to "\\".
+ * is converted to "\\". Printable characters (defined by g_ascii_isprint()) as well as newline
+ * character are not converted.
  *
  * Note that the backslash and newline characters are considered as printable characters and
  * will not be represented by the "\xyz" representation.
@@ -2754,22 +2755,23 @@ gda_binary_to_string (const GdaBinary *bin, guint maxlen)
 
 /**
  * gda_string_to_binary:
- * @str: a string to convert
+ * @str: (allow-none): a string to convert, or %NULL
  *
  * Performs the reverse of gda_binary_to_string() (note that for any "\xyz" succession
  * of 4 characters where "xyz" represents a valid octal value, the resulting read value will
- * be modulo 256)
+ * be modulo 256).
+ *
+ * I @str is %NULL, then an empty (i.e. where the @data part is %NULL) #GdaBinary is created and returned.
  *
- * Returns: (transfer full): a new #GdaBinary if no error were found in @str, or NULL otherwise
+ * Returns: (transfer full): a new #GdaBinary if no error were found in @str, or %NULL otherwise
  */
 GdaBinary *
 gda_string_to_binary (const gchar *str)
 {
 	GdaBinary *bin;
 	glong len = 0, total;
-	gchar *rptr;
-	const gchar *sptr;
-	gchar *retval;
+	const guchar *sptr;
+	guchar *rptr, *retval;
 
 	if (!str) {
 		bin = g_new0 (GdaBinary, 1);
@@ -2780,8 +2782,8 @@ gda_string_to_binary (const gchar *str)
 
 	total = strlen (str);
 	retval = g_new0 (gchar, total + 1);
-	sptr = str;
-	rptr = (gchar *) retval;
+	sptr = (guchar*) str;
+	rptr = retval;
 
 	while (*sptr) {
 		if (*sptr == '\\') {
@@ -2790,13 +2792,15 @@ gda_string_to_binary (const gchar *str)
 				sptr += 2;
 			}
 			else {
+				guint tmp;
 				if ((*(sptr+1) >= '0') && (*(sptr+1) <= '7') &&
 				    (*(sptr+2) >= '0') && (*(sptr+2) <= '7') &&
 				    (*(sptr+3) >= '0') && (*(sptr+3) <= '7')) {
-					*rptr = (*(sptr+1) - '0') * 64 +
+					tmp = (*(sptr+1) - '0') * 64 +
 						(*(sptr+2) - '0') * 8 +
 						(*(sptr+3) - '0');
 					sptr += 4;
+					*rptr = tmp % 256;
 				}
 				else {
 					g_free (retval);
@@ -2814,7 +2818,7 @@ gda_string_to_binary (const gchar *str)
 	}
 
 	bin = g_new0 (GdaBinary, 1);
-	bin->data = (guchar*)retval;
+	bin->data = retval;
 	bin->binary_length = len;
 
 	return bin;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]