summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
26c73fa)
* imap_roomname():
* 256 is double ROOMNAMELEN; calculate it here to show the relation in place
* extract_token() gives us -1 or the stringlength, use it instead of doing another strlen a line below
* use safestrncpy()
* do_imap_match():
* while lowercasing run till \0 rather than doing strlen above
* respect the size of the target buffer...
* For-loop: assign pointers here, since we start using them here; use IsEmptyStr all over the place (also some forgotten ones...)
static void string_append_c(struct string* s, int c)
{
static void string_append_c(struct string* s, int c)
{
int len = 0;
/* Don't do anything if there's no room. */
int len = 0;
/* Don't do anything if there's no room. */
- buf[0] = 0xC0 | (c >> 6);
- buf[1] = 0x80 | (c & 0x3F);
+ UmlChar[0] = 0xC0 | (c >> 6);
+ UmlChar[1] = 0x80 | (c & 0x3F);
len = 2;
}
else if (c <= 0xFFFF)
{
len = 2;
}
else if (c <= 0xFFFF)
{
- buf[0] = 0xE0 | (c >> 12);
- buf[1] = 0x80 | ((c >> 6) & 0x3f);
- buf[2] = 0x80 | (c & 0x3f);
+ UmlChar[0] = 0xE0 | (c >> 12);
+ UmlChar[1] = 0x80 | ((c >> 6) & 0x3f);
+ UmlChar[2] = 0x80 | (c & 0x3f);
- buf[0] = 0xf0 | c >> 18;
- buf[1] = 0x80 | ((c >> 12) & 0x3f);
- buf[2] = 0x80 | ((c >> 6) & 0x3f);
- buf[3] = 0x80 | (c & 0x3f);
+ UmlChar[0] = 0xf0 | c >> 18;
+ UmlChar[1] = 0x80 | ((c >> 12) & 0x3f);
+ UmlChar[2] = 0x80 | ((c >> 6) & 0x3f);
+ UmlChar[3] = 0x80 | (c & 0x3f);
- string_append_sn(s, buf, len);
+ string_append_sn(s, UmlChar, len);
}
/* Reads a UTF8 character from a char*, advancing the pointer. */
}
/* Reads a UTF8 character from a char*, advancing the pointer. */
int imap_roomname(char *rbuf, int bufsize, const char *foldername)
{
int levels;
int imap_roomname(char *rbuf, int bufsize, const char *foldername)
{
int levels;
+ char floorname[ROOMNAMELEN*2];
char roomname[ROOMNAMELEN];
int i;
struct floor *fl;
char roomname[ROOMNAMELEN];
int i;
struct floor *fl;
levels = num_tokens(rbuf, FDELIM);
if (levels > 1)
{
levels = num_tokens(rbuf, FDELIM);
if (levels > 1)
{
/* Extract the main room name. */
/* Extract the main room name. */
- extract_token(floorname, rbuf, 0, FDELIM, sizeof floorname);
- strcpy(roomname, &rbuf[strlen(floorname)+1]);
+ len = extract_token(floorname, rbuf, 0, FDELIM, sizeof floorname);
+ if (len < 0) len = 0;
+ safestrncpy(roomname, &rbuf[len + 1], sizeof(roomname));
/* Try and find it on any floor. */
/* Try and find it on any floor. */
{
int matched, i;
char lcase_text[SIZ], lcase_p[SIZ];
{
int matched, i;
char lcase_text[SIZ], lcase_p[SIZ];
- char *text = lcase_text;
- char *p = lcase_p;
- long len;
-
+ char *text;
+ char *p;
+
/* Copy both strings and lowercase them, in order to
* make this entire operation case-insensitive.
*/
/* Copy both strings and lowercase them, in order to
* make this entire operation case-insensitive.
*/
- len = strlen(supplied_text);
- for (i=0; i<=len; ++i)
+ for (i=0;
+ ((supplied_text[i] != '\0') &&
+ (i < sizeof(lcase_text)));
+ ++i)
lcase_text[i] = tolower(supplied_text[i]);
lcase_text[i] = tolower(supplied_text[i]);
- len = strlen(supplied_p);
- for (i=0; i<=len; ++i)
- p[i] = tolower(supplied_p[i]);
+ lcase_text[i] = '\0';
+
+ for (i=0;
+ ((supplied_p[i] != '\0') &&
+ (i < sizeof(lcase_p)));
+ ++i)
+ lcase_p[i] = tolower(supplied_p[i]);
+ lcase_p[i] = '\0';
- for (; *p; text++, p++) {
+ for (p = lcase_p, text = lcase_text;
+ !IsEmptyStr(p) && !IsEmptyStr(text);
+ text++, p++) {
if ((*text == '\0') && (*p != '*') && (*p != '%')) {
return WILDMAT_ABORT;
}
if ((*text == '\0') && (*p != '*') && (*p != '%')) {
return WILDMAT_ABORT;
}
}
return WILDMAT_ABORT;
case '%':
}
return WILDMAT_ABORT;
case '%':
- while (++p, ((*p == '*') || (*p == '%'))) {
+ while (++p, (!IsEmptyStr(p) && ((*p == '*') || (*p == '%'))))
+ {
/* Consecutive %'s act just like one, but even
* a single star makes the sequence act like
* one star, instead.
/* Consecutive %'s act just like one, but even
* a single star makes the sequence act like
* one star, instead.
* Trailing % matches everything
* without a delimiter.
*/
* Trailing % matches everything
* without a delimiter.
*/
+ while (!IsEmptyStr(text)) {
if (*text == WILDMAT_DELIM) {
return WILDMAT_FALSE;
}
if (*text == WILDMAT_DELIM) {
return WILDMAT_FALSE;
}
- while (*text && (*(text - 1) != WILDMAT_DELIM)) {
+ while (!IsEmptyStr(text) && (*(text - 1) != WILDMAT_DELIM)) {
if ((matched = do_imap_match(text++, p))
!= WILDMAT_FALSE) {
return matched;
if ((matched = do_imap_match(text++, p))
!= WILDMAT_FALSE) {
return matched;