From 329e4ff9c64cbee2e5b3b078b56e99af3f285bcc Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 20 Feb 2013 02:51:40 -0500 Subject: [PATCH] calculate the # of digits with log10 and free str --- termite.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/termite.cc b/termite.cc index 0418bab..1b56863 100644 --- a/termite.cc +++ b/termite.cc @@ -760,15 +760,13 @@ gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, keybind_info *i const char *const text = gtk_entry_get_text(entry); char *fulltext = g_strndup(text, strlen(text) + 1); fulltext[strlen(text)] = (char)event->keyval; - char *str_ptr = (char*)malloc(sizeof(text)); - sprintf(str_ptr, "%d", (int)info->panel.url_list.size()); - int url_num = (int)strlen(str_ptr); - free(str_ptr); - int inp_num = (int)strlen(fulltext); - if (url_num == inp_num) { + size_t base10_digits = static_cast( + log10(static_cast(info->panel.url_list.size())) + 1); + if (strlen(fulltext) == base10_digits) { launch_url(info->config.browser, fulltext, &info->panel); ret = TRUE; } + free(fulltext); } break; case GDK_KEY_Tab: