Skip to content

Commit

Permalink
improve warning()'s handling of messages containing \n
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@85879 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Feb 9, 2024
1 parent 1c37563 commit 7443ac7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,16 @@ static void vwarningcall_dflt(SEXP call, const char *format, va_list ap)
if(dcall[0] == '\0') REprintf(_("Warning:"));
else {
REprintf(_("Warning in %s :"), dcall);
// This did not allow for buf containing line breaks
// We can put the first line on the same line as the warning
// if it fits within LONGWARN.
char buf1[BUFSIZE];
strncpy(buf1, buf, BUFSIZE);
char *p = strstr(buf1, "\n");
if(p) *p = '\0';
if(!(noBreakWarning ||
( mbcslocale && 18 + wd(dcall) + wd(buf) >= LONGWARN) ||
(!mbcslocale && 18 + strlen(dcall) + strlen(buf) >= LONGWARN)))
( mbcslocale && (18 + wd(dcall) + wd(buf1) <= LONGWARN)) ||
(!mbcslocale && (18 + strlen(dcall) + strlen(buf1) <= LONGWARN))))
REprintf("\n ");
}
REprintf(" %s\n", buf);
Expand Down

0 comments on commit 7443ac7

Please sign in to comment.