aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/multicol.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-20 22:33:26 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-20 22:33:26 +0100
commit557371f7b2f2a4e58c20e994124f77b7ed6f01da (patch)
treea04340e868254b5cf5e552a03df9a429e7371bb5 /FICS/multicol.c
parent8704ca522197d22c249cd7f9250055dc841e357d (diff)
Reformatted multicol_store_sorted() and added null checks
Diffstat (limited to 'FICS/multicol.c')
-rw-r--r--FICS/multicol.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/FICS/multicol.c b/FICS/multicol.c
index 785d0fe..4853b3f 100644
--- a/FICS/multicol.c
+++ b/FICS/multicol.c
@@ -54,27 +54,28 @@ PUBLIC int multicol_store(multicol * m, char *str)
return 0;
}
-PUBLIC int multicol_store_sorted(multicol * m, char *str)
-/* use this instead of milticol_store to print a list sorted */
-{
- int i;
- int found = 0;
- if (m->num >= m->arraySize)
- return -1;
- if (!str)
- return -1;
- for (i = m->num; (i > 0) && (!found); i--) {
- if (strcasecmp(str, m->strArray[i - 1]) >= 0) {
- found = 1;
- m->strArray[i] = xstrdup(str);
- } else {
- m->strArray[i] = m->strArray[i - 1];
- }
- }
- if (!found)
- m->strArray[0] = xstrdup(str);
- m->num++;
- return 0;
+PUBLIC int
+multicol_store_sorted(multicol *m, char *str)
+{ // Use this instead of multicol_store() to print a list sorted.
+ int found = 0;
+
+ if (m == NULL || str == NULL || m->num >= m->arraySize)
+ return -1;
+
+ for (int i = m->num; i > 0 && !found; i--) {
+ if (strcasecmp(str, m->strArray[i - 1]) >= 0) {
+ found = 1;
+ m->strArray[i] = xstrdup(str);
+ } else {
+ m->strArray[i] = m->strArray[i - 1];
+ }
+ }
+
+ if (!found)
+ m->strArray[0] = xstrdup(str);
+
+ m->num++;
+ return 0;
}
PUBLIC int