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
23
termite.cc
23
termite.cc
|
@ -136,23 +136,20 @@ 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 (!token) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!errno && end != text) {
|
unsigned long id = strtoul(token, &end, 10);
|
||||||
if (id <= info->url_list.size())
|
if (!errno && end != text && id && id <= info->url_list.size()) {
|
||||||
launch_browser(info->url_list[id - 1].url.get());
|
launch_browser(info->url_list[id - 1].url.get());
|
||||||
|
} else {
|
||||||
switch (*end) {
|
|
||||||
case ',':
|
|
||||||
text = end + 1;
|
|
||||||
continue;
|
|
||||||
case '\0':
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_printerr("url hint invalid: %s\n", text);
|
g_printerr("url hint invalid: %s\n", text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_marker(cairo_t *cr, const char *font, long x, long y, int padding, unsigned id) {
|
static void draw_marker(cairo_t *cr, const char *font, long x, long y, int padding, unsigned id) {
|
||||||
|
|
Loading…
Reference in New Issue