Changeset 65b48ee in code
- Timestamp:
- Apr 22, 2015, 5:29:05 PM (10 years ago)
- Branches:
- master
- Children:
- 8b1683e
- Parents:
- 7ff6405
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
icb.c
r7ff6405 r65b48ee 256 256 struct icb_group *ig = is->group; 257 257 struct icb_session *s; 258 int buflen = 1;258 int res, buflen = 1; 259 259 260 260 if (strlen(msg) == 0) { … … 263 263 } 264 264 265 buflen += snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN,265 res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN, 266 266 is->nick, ICB_M_SEP, msg); 267 if (res < 0) { 268 icb_error(is, "Format error"); 269 return; 270 } 271 buflen += MIN((size_t)res, sizeof buf - 1); 267 272 buf[0] = buflen; 268 273 … … 373 378 va_list ap; 374 379 char buf[ICB_MSGSIZE]; 375 int buflen = 1;380 int res, buflen = 1; 376 381 static const struct { 377 382 int type; … … 395 400 if (type < 0 || type > (int)nitems(msgtab) - 1) 396 401 return; 402 res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c", ICB_M_STATUS, 403 msgtab[type].msg, ICB_M_SEP); 404 if (res < 0) { 405 icbd_log(NULL, LOG_ERR, "Format error in %s", __func__); 406 return; 407 } 408 buflen += MIN((size_t)res, sizeof buf - 1); 409 if ((size_t)buflen >= sizeof buf) { 410 icbd_log(NULL, LOG_ERR, "Status buffer too small"); 411 return; 412 } 397 413 va_start(ap, fmt); 398 buflen += snprintf(&buf[1], sizeof buf - 1, "%c%s%c", ICB_M_STATUS, 399 msgtab[type].msg, ICB_M_SEP); 400 buflen += vsnprintf(&buf[buflen], sizeof buf - buflen, fmt, ap); 414 res = vsnprintf(&buf[buflen], sizeof buf - buflen, fmt, ap); 415 va_end(ap); 416 if (res < 0) { 417 icbd_log(NULL, LOG_ERR, "Format error in %s", __func__); 418 return; 419 } 420 buflen += MIN((size_t)res, sizeof buf - buflen); 401 421 buf[0] = buflen; 402 va_end(ap);403 422 icbd_send(is, buf, buflen + 1); 404 423 } … … 436 455 char buf[ICB_MSGSIZE]; 437 456 va_list ap; 438 int buflen = 1;457 int res, buflen = 1; 439 458 440 459 va_start(ap, fmt); 441 buflen += vsnprintf(&buf[2], sizeof buf - 2, fmt, ap);460 res = vsnprintf(&buf[2], sizeof buf - 2, fmt, ap); 442 461 va_end(ap); 462 if (res < 0) { 463 icbd_log(NULL, LOG_ERR, "Format error"); 464 return; 465 } 466 buflen += MIN((size_t)res, sizeof buf - 2); 443 467 buf[0] = ++buflen; /* account for ICB_M_ERROR */ 444 468 buf[1] = ICB_M_ERROR; … … 625 649 char buf[ICB_MSGSIZE]; 626 650 va_list ap; 627 int buflen = 1;651 int res, buflen = 1; 628 652 629 653 va_start(ap, fmt); 630 buflen += vsnprintf(&buf[1], sizeof buf - 1, fmt, ap);654 res = vsnprintf(&buf[1], sizeof buf - 1, fmt, ap); 631 655 va_end(ap); 656 if (res < 0) { 657 icbd_log(NULL, LOG_ERR, "Format error in %s", __func__); 658 return; 659 } 660 buflen += MIN((size_t)res, sizeof buf - 1); 632 661 buf[0] = buflen; 633 662 icbd_send(is, buf, buflen + 1);
Note:
See TracChangeset
for help on using the changeset viewer.