- Timestamp:
- Aug 24, 2017, 2:41:37 PM (8 years ago)
- Branches:
- master
- Children:
- 4c07461
- Parents:
- c3f5bda
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
icb.c
rc3f5bda rc6e00b9 257 257 struct icb_group *ig = is->group; 258 258 struct icb_session *s; 259 int res, buflen = 1;259 int res, buflen; 260 260 261 261 if (strlen(msg) == 0) { … … 264 264 } 265 265 266 res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN, 267 is->nick, ICB_M_SEP, msg); 268 if (res < 0) { 269 icb_error(is, "Format error"); 270 return; 271 } 272 buflen += MIN((size_t)res, sizeof buf - 1); 273 buf[0] = buflen; 274 275 logger(ig->name, is->nick, msg); 276 277 LIST_FOREACH(s, &ig->sess, entry) { 278 if (s == is) 279 continue; 280 icbd_send(s, buf, buflen + 1); 281 } 266 do { 267 res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN, 268 is->nick, ICB_M_SEP, msg); 269 if (res < 0) { 270 icbd_log(is, LOG_ERR, "Format error in %s", __func__); 271 return; 272 } 273 /* res doesn't include the terminating NUL*/ 274 buflen = MIN((size_t)res + 1, sizeof buf - 1); 275 buf[0] = buflen; 276 277 logger(ig->name, is->nick, msg); 278 279 LIST_FOREACH(s, &ig->sess, entry) { 280 if (s == is) 281 continue; 282 icbd_send(s, buf, buflen + 1); 283 } 284 285 msg += buflen - 1; 286 } while (res > buflen - 1); 282 287 } 283 288 … … 290 295 struct icb_group *ig = is->group; 291 296 struct icb_session *s; 297 char buf[ICB_MSGSIZE]; 292 298 char whom[ICB_MAXNICKLEN]; 299 int res, buflen; 293 300 294 301 icb_vis(whom, to, ICB_MAXNICKLEN, VIS_SP); … … 314 321 } 315 322 } 316 icb_sendfmt(s, "%c%s%c%s", ICB_M_PERSONAL, is->nick, ICB_M_SEP, msg); 323 324 do { 325 res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", 326 ICB_M_PERSONAL, is->nick, ICB_M_SEP, msg); 327 if (res < 0) { 328 icbd_log(is, LOG_ERR, "Format error in %s", __func__); 329 return; 330 } 331 /* res doesn't include the terminating NUL*/ 332 buflen = MIN((size_t)res + 1, sizeof buf - 1); 333 buf[0] = buflen; 334 335 icbd_send(s, buf, buflen + 1); 336 337 msg += buflen - 1; 338 } while (res > buflen - 1); 317 339 } 318 340 … … 659 681 return; 660 682 } 661 buflen += MIN((size_t)res , sizeof buf - 1);683 buflen += MIN((size_t)res + 1, sizeof buf - 1); 662 684 buf[0] = buflen; 663 685 icbd_send(is, buf, buflen + 1);
Note:
See TracChangeset
for help on using the changeset viewer.