Mercurial > vim
comparison src/message.c @ 18309:2047cb93eb0c v8.1.2149
patch 8.1.2149: crash when running out of memory very early
Commit: https://github.com/vim/vim/commit/e3a22cb1ba057381be3e645479a537f8032f119f
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Oct 14 22:01:57 2019 +0200
patch 8.1.2149: crash when running out of memory very early
Problem: Crash when running out of memory very early.
Solution: Do not use IObuff when it's NULL. (closes https://github.com/vim/vim/issues/5052)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 14 Oct 2019 22:15:03 +0200 |
parents | 1c5974759bcd |
children | 9f51d0cef8da |
comparison
equal
deleted
inserted
replaced
18308:9eb04d4799d5 | 18309:2047cb93eb0c |
---|---|
354 int vim_snprintf(char *str, size_t str_m, const char *fmt, ...); | 354 int vim_snprintf(char *str, size_t str_m, const char *fmt, ...); |
355 | 355 |
356 int | 356 int |
357 smsg(const char *s, ...) | 357 smsg(const char *s, ...) |
358 { | 358 { |
359 va_list arglist; | 359 if (IObuff == NULL) |
360 | 360 { |
361 va_start(arglist, s); | 361 // Very early in initialisation and already something wrong, just |
362 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); | 362 // give the raw message so the user at least gets a hint. |
363 va_end(arglist); | 363 return msg((char *)s); |
364 return msg((char *)IObuff); | 364 } |
365 else | |
366 { | |
367 va_list arglist; | |
368 | |
369 va_start(arglist, s); | |
370 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); | |
371 va_end(arglist); | |
372 return msg((char *)IObuff); | |
373 } | |
365 } | 374 } |
366 | 375 |
367 int | 376 int |
368 smsg_attr(int attr, const char *s, ...) | 377 smsg_attr(int attr, const char *s, ...) |
369 { | 378 { |
370 va_list arglist; | 379 if (IObuff == NULL) |
371 | 380 { |
372 va_start(arglist, s); | 381 // Very early in initialisation and already something wrong, just |
373 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); | 382 // give the raw message so the user at least gets a hint. |
374 va_end(arglist); | 383 return msg_attr((char *)s, attr); |
375 return msg_attr((char *)IObuff, attr); | 384 } |
385 else | |
386 { | |
387 va_list arglist; | |
388 | |
389 va_start(arglist, s); | |
390 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); | |
391 va_end(arglist); | |
392 return msg_attr((char *)IObuff, attr); | |
393 } | |
376 } | 394 } |
377 | 395 |
378 int | 396 int |
379 smsg_attr_keep(int attr, const char *s, ...) | 397 smsg_attr_keep(int attr, const char *s, ...) |
380 { | 398 { |
381 va_list arglist; | 399 if (IObuff == NULL) |
382 | 400 { |
383 va_start(arglist, s); | 401 // Very early in initialisation and already something wrong, just |
384 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); | 402 // give the raw message so the user at least gets a hint. |
385 va_end(arglist); | 403 return msg_attr_keep((char *)s, attr, TRUE); |
386 return msg_attr_keep((char *)IObuff, attr, TRUE); | 404 } |
405 else | |
406 { | |
407 va_list arglist; | |
408 | |
409 va_start(arglist, s); | |
410 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); | |
411 va_end(arglist); | |
412 return msg_attr_keep((char *)IObuff, attr, TRUE); | |
413 } | |
387 } | 414 } |
388 | 415 |
389 #endif | 416 #endif |
390 | 417 |
391 /* | 418 /* |
721 * Note: caller must not pass 'IObuff' as 1st argument. | 748 * Note: caller must not pass 'IObuff' as 1st argument. |
722 */ | 749 */ |
723 int | 750 int |
724 semsg(const char *s, ...) | 751 semsg(const char *s, ...) |
725 { | 752 { |
726 /* Skip this if not giving error messages at the moment. */ | 753 // Skip this if not giving error messages at the moment. |
727 if (!emsg_not_now()) | 754 if (!emsg_not_now()) |
728 { | 755 { |
729 va_list ap; | 756 if (IObuff == NULL) |
730 | 757 { |
731 va_start(ap, s); | 758 // Very early in initialisation and already something wrong, just |
732 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); | 759 // give the raw message so the user at least gets a hint. |
733 va_end(ap); | 760 return emsg_core((char_u *)s); |
734 return emsg_core(IObuff); | 761 } |
735 } | 762 else |
736 return TRUE; /* no error messages at the moment */ | 763 { |
764 va_list ap; | |
765 | |
766 va_start(ap, s); | |
767 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); | |
768 va_end(ap); | |
769 return emsg_core(IObuff); | |
770 } | |
771 } | |
772 return TRUE; // no error messages at the moment | |
737 } | 773 } |
738 #endif | 774 #endif |
739 | 775 |
740 /* | 776 /* |
741 * Same as emsg(...), but abort on error when ABORT_ON_INTERNAL_ERROR is | 777 * Same as emsg(...), but abort on error when ABORT_ON_INTERNAL_ERROR is |
762 void | 798 void |
763 siemsg(const char *s, ...) | 799 siemsg(const char *s, ...) |
764 { | 800 { |
765 if (!emsg_not_now()) | 801 if (!emsg_not_now()) |
766 { | 802 { |
767 va_list ap; | 803 if (IObuff == NULL) |
768 | 804 { |
769 va_start(ap, s); | 805 // Very early in initialisation and already something wrong, just |
770 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); | 806 // give the raw message so the user at least gets a hint. |
771 va_end(ap); | 807 emsg_core((char_u *)s); |
772 emsg_core(IObuff); | 808 } |
809 else | |
810 { | |
811 va_list ap; | |
812 | |
813 va_start(ap, s); | |
814 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); | |
815 va_end(ap); | |
816 emsg_core(IObuff); | |
817 } | |
773 } | 818 } |
774 # ifdef ABORT_ON_INTERNAL_ERROR | 819 # ifdef ABORT_ON_INTERNAL_ERROR |
775 abort(); | 820 abort(); |
776 # endif | 821 # endif |
777 } | 822 } |
3504 | 3549 |
3505 #if defined(FEAT_EVAL) || defined(PROTO) | 3550 #if defined(FEAT_EVAL) || defined(PROTO) |
3506 void | 3551 void |
3507 give_warning2(char_u *message, char_u *a1, int hl) | 3552 give_warning2(char_u *message, char_u *a1, int hl) |
3508 { | 3553 { |
3509 vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1); | 3554 if (IObuff == NULL) |
3510 give_warning(IObuff, hl); | 3555 { |
3556 // Very early in initialisation and already something wrong, just give | |
3557 // the raw message so the user at least gets a hint. | |
3558 give_warning((char_u *)message, hl); | |
3559 } | |
3560 else | |
3561 { | |
3562 vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1); | |
3563 give_warning(IObuff, hl); | |
3564 } | |
3511 } | 3565 } |
3512 #endif | 3566 #endif |
3513 | 3567 |
3514 /* | 3568 /* |
3515 * Advance msg cursor to column "col". | 3569 * Advance msg cursor to column "col". |