Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorRolf Bjarne Kvinge <rolf@xamarin.com>2012-03-30 15:40:01 +0400
committerRolf Bjarne Kvinge <rolf@xamarin.com>2012-03-30 15:44:03 +0400
commitda333100c1ff5c8c1fab022b8e220f239b7c93e5 (patch)
tree195587555e3e3ba32a47cb86ea739765930e0501 /eglib
parent0d5bb49660a3898d16300db2dd37e357f645b0f3 (diff)
Fix g_strreverse to handle empty strings
Diffstat (limited to 'eglib')
-rw-r--r--eglib/src/gstr.c3
-rw-r--r--eglib/test/string-util.c24
2 files changed, 20 insertions, 7 deletions
diff --git a/eglib/src/gstr.c b/eglib/src/gstr.c
index fccf2651db2..0f66a43372e 100644
--- a/eglib/src/gstr.c
+++ b/eglib/src/gstr.c
@@ -357,6 +357,9 @@ g_strreverse (gchar *str)
if (str == NULL)
return NULL;
+ if (*str == 0)
+ return str;
+
for (i = 0, j = strlen (str) - 1; i < j; i++, j--) {
c = str [i];
str [i] = str [j];
diff --git a/eglib/test/string-util.c b/eglib/test/string-util.c
index 14d24d6ac77..3dbd738aba7 100644
--- a/eglib/test/string-util.c
+++ b/eglib/test/string-util.c
@@ -296,27 +296,37 @@ test_split_set ()
RESULT
test_strreverse ()
{
+ RESULT res = OK;
gchar *a = g_strdup ("onetwothree");
gchar *a_target = "eerhtowteno";
gchar *b = g_strdup ("onetwothre");
gchar *b_target = "erhtowteno";
+ gchar *c = g_strdup ("");
+ gchar *c_target = "";
g_strreverse (a);
if (strcmp (a, a_target)) {
- g_free (b);
- g_free (a);
- return FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
+ res = FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
+ goto cleanup;
}
g_strreverse (b);
if (strcmp (b, b_target)) {
- g_free (b);
- g_free (a);
- return FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+ res = FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+ goto cleanup;
}
+
+ g_strreverse (c);
+ if (strcmp (c, c_target)) {
+ res = FAILED("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+ goto cleanup;
+ }
+
+cleanup:
+ g_free (c);
g_free (b);
g_free (a);
- return OK;
+ return res;
}
RESULT