switch to strtok_r for comma-separator urls
this avoids an infinite loop when there is an invalid hint number
This commit is contained in:
parent
4f515865f6
commit
eb6389e042
27
termite.cc
27
termite.cc
|
@ -136,22 +136,19 @@ static void launch_url(const char *text, search_panel_info *info) {
|
||||||
char *end;
|
char *end;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
while (true) {
|
std::unique_ptr<char, decltype(&free)> copy(strdup(text), free);
|
||||||
unsigned long id = strtoul(text, &end, 10);
|
for (char *s_ptr = copy.get(), *saveptr; ; s_ptr = nullptr) {
|
||||||
|
const char *token = strtok_r(s_ptr, ",", &saveptr);
|
||||||
if (!errno && end != text) {
|
if (!token) {
|
||||||
if (id <= info->url_list.size())
|
break;
|
||||||
launch_browser(info->url_list[id - 1].url.get());
|
}
|
||||||
|
|
||||||
switch (*end) {
|
unsigned long id = strtoul(token, &end, 10);
|
||||||
case ',':
|
if (!errno && end != text && id && id <= info->url_list.size()) {
|
||||||
text = end + 1;
|
launch_browser(info->url_list[id - 1].url.get());
|
||||||
continue;
|
} else {
|
||||||
case '\0':
|
g_printerr("url hint invalid: %s\n", text);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
g_printerr("url hint invalid: %s\n", text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue