pidgin/pidgin

Verify some user input in nullclient.

2019-10-02, Elliott Sales de Andrade
94c809048a88
Parents 3c0d4b834fea
Children ce96d4639dc7
Verify some user input in nullclient.
--- a/libpurple/example/nullclient.c Wed Oct 02 03:36:46 2019 -0400
+++ b/libpurple/example/nullclient.c Wed Oct 02 03:43:56 2019 -0400
@@ -192,16 +192,21 @@
}
g_list_free(list);
- printf("Select the protocol [0-%d]: ", i-1);
- res = fgets(name, sizeof(name), stdin);
- if (!res) {
- fprintf(stderr, "Failed to gets protocol selection.");
- abort();
+ num = -1;
+ while (num < 0 || num >= i) {
+ printf("Select the protocol [0-%d]: ", i - 1);
+ res = fgets(name, sizeof(name), stdin);
+ if (!res) {
+ fprintf(stderr, "Failed to get protocol selection.");
+ abort();
+ }
+ if (sscanf(name, "%d", &num) != 1) {
+ num = -1;
+ }
}
- if (sscanf(name, "%d", &num) == 1)
- protocol = g_list_nth_data(names, num);
+ protocol = g_list_nth_data(names, num);
if (!protocol) {
- fprintf(stderr, "Failed to gets protocol.");
+ fprintf(stderr, "Failed to get protocol.");
abort();
}