Skip to content

Commit 8430074

Browse files
committed
OSReport: fix sending message when its larger than the buffer
1 parent 52c525a commit 8430074

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

libogc/sys_report.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,13 @@ static ssize_t __uart_stdio_write(struct _reent *r, void *fd, const char *ptr, s
7070
size_t buflen = len;
7171
if (buflen > __outsz) buflen = __outsz;
7272
left -= buflen;
73-
while(buflen>0) {
73+
for(int i = 0; i < buflen; i++) {
7474
char ch = *p++;
7575
if(ch=='\r' && *p == '\n') continue;
7676
if (ch=='\n') ch = '\r';
7777
*buf++ = ch;
78-
buflen--;
7978
}
80-
__uart_write(__outstr,len);
79+
__uart_write(__outstr, buflen);
8180
}
8281
return len;
8382
}
@@ -107,11 +106,11 @@ void SYS_Report (char const *const fmt_, ...)
107106

108107
va_list args;
109108

109+
memset(__outstr, 0, __outsz);
110110
va_start(args, fmt_);
111-
len=vsnprintf(__outstr,256,fmt_,args);
111+
len=vsnprintf(__outstr,__outsz,fmt_,args);
112112
va_end(args);
113113

114-
__uart_stdio_write(NULL, 0, __outstr, len);
115-
114+
__uart_stdio_write(NULL, 0, __outstr, len >= __outsz ? (__outsz -1) : len);
116115
}
117116

0 commit comments

Comments
 (0)