lkml.org 
[lkml]   [2001]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: Linux 2.4.6-ac5
Alan Cox wrote:
>
> o Add snprintf/vsnprintf to the kernel (Crutcher Dunnavant)

Nice.

Couple of things:

+ if (end < buf - 1) {
+ end = ((void *) -1);
+ size = end - buf + 1;
+ }

This is odd. It seems to be saying that if we're trying to
wrap around the end of memory, we terminate at the end of
memory, yes? What is the intent here?


Also, my manpage says that vsnprintf should return -1
if it truncated the output. Your implementation
doesn't do that, but trivially could.

Alan, we can drop the overrun-detector from printk now.

--- linux-2.4.6-ac5/kernel/printk.c Tue Jul 17 00:59:21 2001
+++ ac/kernel/printk.c Tue Jul 17 01:22:59 2001
@@ -394,11 +394,7 @@ asmlinkage int printk(const char *fmt, .
unsigned long flags;
int printed_len;
char *p;
- unsigned long sr_copy;
- static struct {
- char buf[1024];
- unsigned long semi_random;
- } printk_buf;
+ static char printk_buf[1024];
static int log_level_unknown = 1;

if (oops_in_progress) {
@@ -412,19 +408,20 @@ asmlinkage int printk(const char *fmt, .
spin_lock_irqsave(&logbuf_lock, flags);

/* Emit the output into the temporary buffer */
- printk_buf.semi_random += jiffies;
- sr_copy = printk_buf.semi_random;
va_start(args, fmt);
- printed_len = vsprintf(printk_buf.buf, fmt, args);
+ printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
+ if (printed_len == -1) {
+ /* vsnprintf truncated it, but printk() callers don't
+ * expect a -1 return value */
+ printed_len = sizeof(printk_buf) - 1;
+ }
va_end(args);
- if (sr_copy != printk_buf.semi_random)
- panic("buffer overrun in printk()");

/*
* Copy the output into log_buf. If the caller didn't provide
* appropriate log level tags, we insert them here
*/
- for (p = printk_buf.buf; *p; p++) {
+ for (p = printk_buf; *p; p++) {
if (log_level_unknown) {
if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>') {
emit_log_char('<');
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 12:57    [W:0.039 / U:0.276 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site