# HG changeset patch # User Matti Hamalainen # Date 1288441174 -10800 # Node ID 352ec3c300e48227787c11d74ff6c14aed33f5c6 # Parent 4235ff4ced04526e48d9645ded54863398d11296 A different initialization. diff -r 4235ff4ced04 -r 352ec3c300e4 nnchat.c --- a/nnchat.c Sat Oct 30 15:07:03 2010 +0300 +++ b/nnchat.c Sat Oct 30 15:19:34 2010 +0300 @@ -534,13 +534,17 @@ int handleProtocol(const int sock, const char *buf, const ssize_t bufLen) { + static BOOL protoCmdsInit = FALSE; int i; + + if (!protoCmdsInit) { + for (i = 0; i < nprotoCmds; i++) + protoCmds[i].len = strlen(protoCmds[i].cmd); + protoCmdsInit = TRUE; + } for (i = 0; i < nprotoCmds; i++) { ssize_t cmdLen = protoCmds[i].len; - if (cmdLen < 0) - cmdLen = protoCmds[i].len = strlen(protoCmds[i].cmd); - if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) return protoCmds[i].handler(sock, buf + cmdLen); }