Mercurial > hg
changeset 419:2f9852610cf4
Small code review
Some clean up and security checks
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 02 Sep 2005 20:34:17 +0200 |
parents | 05bcc91b8699 |
children | 04a0b450380b |
files | mcabber/src/jabglue.c mcabber/src/screen.c mcabber/src/utils.c mcabber/src/utils.h |
diffstat | 4 files changed, 22 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/src/jabglue.c Thu Sep 01 23:48:46 2005 +0200 +++ b/mcabber/src/jabglue.c Fri Sep 02 20:34:17 2005 +0200 @@ -100,7 +100,7 @@ char *alias; while ((alias = g_strdup(jid)) == NULL) - usleep(100); + safe_usleep(100); if ((ptr = strchr(alias, '/')) != NULL) { *ptr = 0; @@ -196,12 +196,12 @@ char *cid; if (!online) { - usleep(10000); + safe_usleep(10000); return; } if (jc && jc->state == JCONN_STATE_CONNECTING) { - usleep(75000); + safe_usleep(75000); jab_start(jc); return; }
--- a/mcabber/src/screen.c Thu Sep 01 23:48:46 2005 +0200 +++ b/mcabber/src/screen.c Fri Sep 02 20:34:17 2005 +0200 @@ -301,7 +301,7 @@ tmp->win = newwin(lines, cols, y, x); while (!tmp->win) { - usleep(250); + safe_usleep(250); tmp->win = newwin(lines, cols, y, x); } wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL)); @@ -393,7 +393,7 @@ // You need to set it to the whole prefix length + 1 if (line) { if (line->timestamp) { - strftime(date, 35, "%m-%d %H:%M", localtime(&line->timestamp)); + strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp)); } else strcpy(date, " "); if (line->flags & HBB_PREFIX_INFO) { @@ -1159,8 +1159,7 @@ // First message line (we skip leading empty lines) num = 0; if (line[0]) { - multiline = g_new(char, strlen(line)+1); - strcpy(multiline, line); + multiline = g_strdup(line); num++; } else return; @@ -1327,7 +1326,8 @@ } strcpy(tmpLine, ptr_inputline); - strcpy(ptr_inputline, text); ptr_inputline += len; + strcpy(ptr_inputline, text); + ptr_inputline += len; strcpy(ptr_inputline, tmpLine); } @@ -1535,8 +1535,7 @@ } else { // down-history // Use next history line instead of a blank line const char *l = scr_cmdhisto_next("", 0); - if (l) - strcpy(inputLine, l); + if (l) strcpy(inputLine, l); // Reset backup history line cmdhisto_backup[0] = 0; } @@ -1545,18 +1544,14 @@ { const char *l = scr_cmdhisto_prev(inputLine, ptr_inputline-inputLine); - if (l) { - strcpy(inputLine, l); - } + if (l) strcpy(inputLine, l); } break; case KEY_DOWN: { const char *l = scr_cmdhisto_next(inputLine, ptr_inputline-inputLine); - if (l) { - strcpy(inputLine, l); - } + if (l) strcpy(inputLine, l); } break; case KEY_PPAGE:
--- a/mcabber/src/utils.c Thu Sep 01 23:48:46 2005 +0200 +++ b/mcabber/src/utils.c Fri Sep 02 20:34:17 2005 +0200 @@ -223,3 +223,12 @@ return retval; } + +// Should only be used for delays < 1s +inline void safe_usleep(unsigned int usec) +{ + struct timespec req; + req.tv_sec = 0; + req.tv_nsec = (long)usec * 1000L; + nanosleep(&req, NULL); +}
--- a/mcabber/src/utils.h Thu Sep 01 23:48:46 2005 +0200 +++ b/mcabber/src/utils.h Fri Sep 02 20:34:17 2005 +0200 @@ -9,4 +9,6 @@ int to_iso8601(char *dststr, time_t timestamp); time_t from_iso8601(const char *timestamp, int utc); +inline void safe_usleep(unsigned int usec); /* Only for delays < 1s */ + #endif