summaryrefslogtreecommitdiff
blob: ae6ff91bb9bf924a2f1188163d175f3a881c358f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
diff --git a/src/string.c b/src/string.c
index 1acfab2..bea6e71 100644
--- a/src/string.c
+++ b/src/string.c
@@ -153,7 +153,7 @@ EXPORT_SYMBOL char **HX_split(const char *str, const char *delim,
 		}
 	}
 
-	if (max == 0)
+	if (max == 0 || *cp < max)
 		max = *cp;
 	else if (*cp > max)
 		*cp = max;
diff --git a/src/tx-string.cpp b/src/tx-string.cpp
index 4e9a534..cc2cbf8 100644
--- a/src/tx-string.cpp
+++ b/src/tx-string.cpp
@@ -142,6 +142,17 @@ static void t_split(void)
 	free(a1);
 }
 
+static void t_split2(void)
+{
+	static const char tmp[] = "";
+	int c = 0;
+	char **a;
+
+	a = HX_split(tmp, " ", &c, 6);
+	printf("Got %d fields\n", c);
+	HX_zvecfree(a);
+}
+
 static void t_quote(void)
 {
 	char *fm = NULL;
@@ -178,6 +189,7 @@ int main(int argc, const char **argv)
 	t_strncat();
 	t_strsep();
 	t_split();
+	t_split2();
 	t_quote();
 	HXmc_free(tx);
 	HX_exit();