Re: [2.6 patch] kill IN_STRING_C

From: linux-os
Date: Mon Nov 08 2004 - 14:27:26 EST

On Mon, 8 Nov 2004, Adrian Bunk wrote:

On Mon, Nov 08, 2004 at 07:04:13PM +0100, Pawe?? Sikora wrote:
On Monday 08 of November 2004 17:31, you wrote:
On Mon, Nov 08, 2004 at 05:19:35PM +0100, Andi Kleen wrote:
Rethinking it, I don't even understand the sprintf example in your
changelog entry - shouldn't an inclusion of kernel.h always get it

Newer gcc rewrites sprintf(buf,"%s",str) to strcpy(buf,str)

Which gcc is "Newer"?

My gcc 3.4.2 didn't show this problem.

#include <stdio.h>
#include <string.h>
char buf[128];
void test(char *str)
sprintf(buf, "%s", str);
jmp strcpy

This is the userspace example.

The kernel example is:

#include <linux/string.h>
#include <linux/kernel.h>

char buf[128];
void test(char *str)
sprintf(buf, "%s", str);

This results with gcc-3.4 (GCC) 3.4.2 (Debian 3.4.2-3) in:

.file "test.c"
.section .rodata.str1.1,"aMS",@progbits,1
.string "%s"
.p2align 4,,15
.globl test
.type test, @function
pushl %eax
pushl $.LC0
pushl $buf
call sprintf
addl $12, %esp
.size test, .-test
.globl buf
.align 32
.type buf, @object
.size buf, 128
.zero 128
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.2 (Debian 3.4.2-3)"


On this compiler 3.3.3, -O2 will cause it to use strcpy().

Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by John Ashcroft.
98.36% of all statistics are fiction.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at