# HG changeset patch # User Nathan Walp # Date 1048351421 0 # Node ID e4bfaba117e477eff655cbc6e19d6799e0154ca4 # Parent 3755ec4e39518300cc4ceb2c4456a415e8c070d9 [gaim-migrate @ 5182] the real solution is to count string length better ;-) committer: Tailor Script diff -r 3755ec4e3951 -r e4bfaba117e4 src/buddy.c --- a/src/buddy.c Sat Mar 22 16:15:16 2003 +0000 +++ b/src/buddy.c Sat Mar 22 16:43:41 2003 +0000 @@ -894,37 +894,29 @@ } if(tmp) { - char *temp; - + char buf[32]; + char *c = tmp; + int length = 0, vis=0; + gboolean inside = FALSE; g_strdelimit(tmp, "\n", ' '); - if(strlen(tmp) > 20) { - char *c1, *c2; - - statustext = g_strdup_printf("%.20s... ", tmp); - - if ((c1 = strrchr(statustext, '&')) != NULL) { - if ((c2 = strrchr(statustext, ';')) == NULL || - c2 < c1) { - - char *new_statustext; - - /* We must escape this broken entity. */ - new_statustext = g_new0(char, strlen(statustext) + 5); + while(*c && vis < 20) { + if(*c == '&') + inside = TRUE; + if(!inside) + vis++; + if(*c == ';') + inside = FALSE; + length++; + c++; /* this is fun */ + } - strncpy(new_statustext, statustext, c1 - statustext); - sprintf(new_statustext + (c1 - statustext), - "&%s", c1 + 1); - - g_free(statustext); + if(vis == 20) + g_snprintf(buf, sizeof(buf), "%%.%ds...", length); + else + g_snprintf(buf, sizeof(buf), "%%s "); - statustext = new_statustext; - } - } - - } - else - statustext = g_strdup_printf("%s ", tmp); + statustext = g_strdup_printf(buf, tmp); g_free(tmp); }