Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-120121-160161-200201-240241-280281-320321-360361-

Code explanation

Name: Anonymous 2012-01-11 12:49

Can somebody explain why this code outputs what it does?

// tested with Core 2 Duo, Core 2 Quad and Xeon
// tested with gcc4.1.2 gcc4.4.3 and gcc4.6.1
// compile with: gcc -O0 -m32
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>

jmp_buf p;
void (*q)();

const char *data =
    "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
    "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
    "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
    "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
    "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
    "\x55\x90\x90\x89\xe5\x90\x90\x90"
    "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
    "\x60\x09\x0e\x13\x14\x01\x0c\x0c"
    "\xc0\x07\x05\x0e\x14\x0f\x0f\x60"
    "\x00\x67\x6f\x74\x6f\x20\x63\x6f"
    "\x6e\x73\x69\x64\x65\x72\x65\x64"
    "\x20\x68\x61\x72\x6d\x66\x75\x6c"
    "\x6c\x00\x90\x90\x1c\x1b\x0a\x20";

int f(int x)
{
    static int b = 0; static int s = 0;
    int a = 0, t;
    if (!s) {
        a = b; b = x;
    } else {
        a = x; t = b;
        do {
            a ^= b;
            b = (a^b) & b;
            b <<= 1;
        } while (b);
        b = t;
    }
    s = (s+1) % 2;
    return a;
}

int g(int i, int *j)
{
    *j = i;
    i = (int) putchar;
    if (*j == (48 << 1)) 
        __asm volatile (
                "movl 8(%ebp),%eax;"
                "leave;"
                "ret"
                );
    return (int) puts;
}

void h(int i)
{
    int b;
    q = (void(*)()) g(i++[data],&b);
    for (f(b);*(data+i)!=b;++i,f(b))
        q(f(i[data])%0xff);
}

void sh(int s)
{
    if (s == 010)
        ((void(*)())g(s,&s))("F");
    longjmp(p,s);
}

int main(void)
{
    int base, addr = 0xffffffff, offs = 16;
    int a = 11, b = 32, i = 25;
    int s = 8, t = 1, u = 4;
    ((void(*)()) data)(&a,&b);
    ((void(*)()) data)(&b,&t);
    ((void(*)()) data)(&t,&s);
    addr ^= a;
       a ^= addr;
    addr ^= a;
    base = ((int(*)())data+addr)();
    if (a == -1)
        goto over;
    puts("A");

    base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
    h(base+addr+offs);
    exit(0);

over:
    signal(t,sh);signal(s,sh);signal(u,sh);

    if (!(s = setjmp(p))) {
        q = (void(*)()) g(0x30, &a);
        q(data + a + i);
        s = a / (b-1);
        puts("B");
    } else if (s == 0xb) {
        puts("C");
        ((int(*)(int)) data+addr+(offs/2))(base);
    } else {
        puts("D");
        *((int*) base+s) = 0xffffffff;
    }
   
    puts("E");
    return 1;
}

Name: Anonymous 2012-01-11 12:52

I see no code in [code] tags.

Name: Anonymous 2012-01-11 12:53

>>2
Sorry, I'm new to the text boards.

http://pastebin[dot]com/uPHf2wZU

Name: Anonymous 2012-01-11 12:53

It outputs Segmentation fault, I guess this has something to do with an address being mishandled.

Name: Anonymous 2012-01-11 12:53


const char *data =
    "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
    "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
    "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
    "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
    "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
    "\x55\x90\x90\x89\xe5\x90\x90\x90"
    "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
    "\x60\x09\x0e\x13\x14\x01\x0c\x0c"
    "\xc0\x07\x05\x0e\x14\x0f\x0f\x60"
    "\x00\x67\x6f\x74\x6f\x20\x63\x6f"
    "\x6e\x73\x69\x64\x65\x72\x65\x64"
    "\x20\x68\x61\x72\x6d\x66\x75\x6c"
    "\x6c\x00\x90\x90\x1c\x1b\x0a\x20";


\x90Nop

Stopped reading right there. Is this a fancy stack smasher?

Name: Anonymous 2012-01-11 12:54


// tested with Core 2 Duo, Core 2 Quad and Xeon
// tested with gcc4.1.2 gcc4.4.3 and gcc4.6.1
// compile with: gcc -O0 -m32
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>

jmp_buf p;
void (*q)();

const char *data =
    "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
    "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
    "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
    "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
    "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
    "\x55\x90\x90\x89\xe5\x90\x90\x90"
    "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
    "\x60\x09\x0e\x13\x14\x01\x0c\x0c"
    "\xc0\x07\x05\x0e\x14\x0f\x0f\x60"
    "\x00\x67\x6f\x74\x6f\x20\x63\x6f"
    "\x6e\x73\x69\x64\x65\x72\x65\x64"
    "\x20\x68\x61\x72\x6d\x66\x75\x6c"
    "\x6c\x00\x90\x90\x1c\x1b\x0a\x20";

int f(int x)
{
    static int b = 0; static int s = 0;
    int a = 0, t;
    if (!s) {
        a = b; b = x;
    } else {
        a = x; t = b;
        do {
            a ^= b;
            b = (a^b) & b;
            b <<= 1;
        } while (b);
        b = t;
    }
    s = (s+1) % 2;
    return a;
}

int g(int i, int *j)
{
    *j = i;
    i = (int) putchar;
    if (*j == (48 << 1))
        __asm volatile (
                "movl 8(%ebp),%eax;"
                "leave;"
                "ret"
                );
    return (int) puts;
}

void h(int i)
{
    int b;
    q = (void(*)()) g(i++[data],&b);
    for (f(b);*(data+i)!=b;++i,f(b))
        q(f(i[data])%0xff);
}

void sh(int s)
{
    if (s == 010)
        ((void(*)())g(s,&s))("F");
    longjmp(p,s);
}

int main(void)
{
    int base, addr = 0xffffffff, offs = 16;
    int a = 11, b = 32, i = 25;
    int s = 8, t = 1, u = 4;
    ((void(*)()) data)(&a,&b);
    ((void(*)()) data)(&b,&t);
    ((void(*)()) data)(&t,&s);
    addr ^= a;
       a ^= addr;
    addr ^= a;
    base = ((int(*)())data+addr)();
    if (a == -1)
        goto over;
    puts("A");

    base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
    h(base+addr+offs);
    exit(0);

over:
    signal(t,sh);signal(s,sh);signal(u,sh);

    if (!(s = setjmp(p))) {
        q = (void(*)()) g(0x30, &a);
        q(data + a + i);
        s = a / (b-1);
        puts("B");
    } else if (s == 0xb) {
        puts("C");
        ((int(*)(int)) data+addr+(offs/2))(base);
    } else {
        puts("D");
        *((int*) base+s) = 0xffffffff;
    }
  
    puts("E");
    return 1;
}

Name: Anonymous 2012-01-11 12:54

The output is undefined as it uses a lot of non-portable conventions.

Name: Anonymous 2012-01-11 12:55

>>5
>XOR, XOR, XOR
It looks like a swap function to me

Name: Anonymous 2012-01-11 12:56

>>7
It says in the comments what to compile it with on where

Name: Anonymous 2012-01-11 12:56

I'm not running that.

Name: Anonymous 2012-01-11 12:57

Lots of people who can't read the comments here.

>>10
>>9
>>8
>>7
>>6
>>5
>>4
goto considered harmfull
F
D
C
A
install gentoo

Name: Anonymous 2012-01-11 12:58

>>9
Really? Where does it say where it should be compiled?

Name: Anonymous 2012-01-11 12:59

>core 2 duo, core 2 quad, xeon
Pretty clear you need to run it on a IA32/x86_64 of some sort.

Name: Anonymous 2012-01-11 12:59

>>9
Well you are a dumb Jew.

Name: Anonymous 2012-01-11 13:00

On my machine it outputs Segmentation fault, I guess that's because it relies on undefined behavior.

Name: Anonymous 2012-01-11 13:01

>>9
I specialize in the standard, not some obscure toy subset language.

Name: Anonymous 2012-01-11 13:02

>>16
>not doing hw specific coding ever
why are you even here

Name: Anonymous 2012-01-11 13:02

>>15
unable to compile with gcc -m32 -O0

Name: [code] tags advocate 2012-01-11 13:03


/ tested with Core 2 Duo, Core 2 Quad and Xeon
 // tested with gcc4.1.2 gcc4.4.3 and gcc4.6.1
 // compile with: gcc -O0 -m32
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <setjmp.h>

 jmp_buf p;
 void (*q)();

 const char *data =
     "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
     "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
     "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
     "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
     "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
     "\x55\x90\x90\x89\xe5\x90\x90\x90"
     "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
     "\x60\x09\x0e\x13\x14\x01\x0c\x0c"
     "\xc0\x07\x05\x0e\x14\x0f\x0f\x60"
     "\x00\x67\x6f\x74\x6f\x20\x63\x6f"
     "\x6e\x73\x69\x64\x65\x72\x65\x64"
     "\x20\x68\x61\x72\x6d\x66\x75\x6c"
     "\x6c\x00\x90\x90\x1c\x1b\x0a\x20";

 int f(int x)
 {
     static int b = 0; static int s = 0;
     int a = 0, t;
     if (!s) {
         a = b; b = x;
     } else {
         a = x; t = b;
         do {
             a ^= b;
             b = (a^b) & b;
             b <<= 1;
         } while (b);
         b = t;
     }
     s = (s+1) % 2;
     return a;
 }

 int g(int i, int *j)
 {
     *j = i;
     i = (int) putchar;
     if (*j == (48 << 1)) 
         __asm volatile (
                 "movl 8(%ebp),%eax;"
                 "leave;"
                 "ret"
                 );
     return (int) puts;
 }

 void h(int i)
 {
     int b;
     q = (void(*)()) g(i++[data],&b);
     for (f(b);*(data+i)!=b;++i,f(b))
         q(f(i[data])%0xff);
 }

 void sh(int s)
 {
     if (s == 010)
         ((void(*)())g(s,&s))("F");
     longjmp(p,s);
 }

 int main(void)
 {
     int base, addr = 0xffffffff, offs = 16;
     int a = 11, b = 32, i = 25;
     int s = 8, t = 1, u = 4;
     ((void(*)()) data)(&a,&b);
     ((void(*)()) data)(&b,&t);
     ((void(*)()) data)(&t,&s);
     addr ^= a;
        a ^= addr;
     addr ^= a;
     base = ((int(*)())data+addr)();
     if (a == -1)
         goto over;
     puts("A");

     base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
     h(base+addr+offs);
     exit(0);

 over:
     signal(t,sh);signal(s,sh);signal(u,sh);

     if (!(s = setjmp(p))) {
         q = (void(*)()) g(0x30, &a);
         q(data + a + i);
         s = a / (b-1);
         puts("B");
     } else if (s == 0xb) {
         puts("C");
         ((int(*)(int)) data+addr+(offs/2))(base);
     } else {
         puts("D");
         *((int*) base+s) = 0xffffffff;
     }
    
     puts("E");
     return 1;
 }

Name: Anonymous 2012-01-11 13:04

>>15
>>7

 // tested with Core 2 Duo, Core 2 Quad and Xeon
 // tested with gcc4.1.2 gcc4.4.3 and gcc4.6.1
 // compile with: gcc -O0 -m32

Name: Anonymous 2012-01-11 13:06

Seriously, /prog/? You disappoint me. Even /g/ managed to compile and run it at least

Name: Anonymous 2012-01-11 13:08

__asm is a reserved identifier, so your code isn't even C, the parts of the code that might C is full of undefined behavior.

In short you are a fucking retard who should fuck off back to /g/.

Name: Anonymous 2012-01-11 13:10

>>21
Well, that's prove that we're superior to /g/ as we will not compile and run suspiciously looking code(and I'm not going to setup new virtual machine just because I got dubs.)

Only /g/ can be so stupid. And /b/, speaking of which /polecat kebabs/.

Name: Anonymous 2012-01-11 13:10

>>22
>hurr i have never done any hw specific code

Name: Anonymous 2012-01-11 13:12

>>23
you can run it in a jail or you can even do a hex dump, no running involved

Name: Anonymous 2012-01-11 13:12

And since >>22 stole dubs while I was writing reply, I'm inclined to setup vm even less now.

Name: Anonymous 2012-01-11 13:13

>>26
just set up a jail, vm isn't required

Name: Anonymous 2012-01-11 13:14

>>21
I ain't gonna switch off from my super ricer desktop to my
obscure gcc compilin desktop just to see a stack smashing warning.

Name: Anonymous 2012-01-11 13:15

>>28
>stack smash
>implying you need to reboot after one
lulwut

Name: Anonymous 2012-01-11 13:17

>>24
I have but I assure you it was a lot better than this undefined piece of shit.

Name: Anonymous 2012-01-11 13:17

~/prog$ gcc -m32 -O0 obscure.c && ./a.out
goto considered harmfull
F
D
C
A
install gentoo

Name: Anonymous 2012-01-11 13:18

>>30
The code is intentionally retarded fuckwit

Name: Anonymous 2012-01-11 13:18

>>30
But you're still not clever enough to figure it out

Name: Anonymous 2012-01-11 13:22

>>32,33
Okay listen you fucking retard, read this and understand it.

__asm is a reserved identifier so the code is not C

The parts of the code that might be C, is full of undefined behavior, so there is nothing to figure out, what it outputs is undefined.

There you go fucknut now fuck off back to /g/ you stupid piece of shit.

Name: Anonymous 2012-01-11 13:23

>>34
>__asm is a reserved identifier so the code is not C
And exactly what is your point? Nowhere did OP claim that it was C.

Name: Anonymous 2012-01-11 13:24

>>34
Dude, no where does anyone claim that it is C. OP asked for the program flow. It certainly does compile and run. You're just being an ignorant dick.

Name: Anonymous 2012-01-11 13:24

>>35
That's implicit by asking us to compile it with a C compiler, are you mentally challenged?

Name: Anonymous 2012-01-11 13:25

>>36
It doesn't compile on my machine.

Name: Anonymous 2012-01-11 13:26

>>37
GCC compiles much more than C, you moron. GCC compiles both C and C++, and it also assembles and links. It even supports Java for fuck sake.

GCC is a compiler suite, not a C compiler. You are a fucking idiot and should kill yourself

Name: Anonymous 2012-01-11 13:27

>>37
GCC isn't a C compiler, it is the GNU compiler suite. It supports everything from Ada to Fortran to Java. It is also a assembler, if you haven't noticed.

Name: Anonymous 2012-01-11 13:29

>>38
Are you using gcc?

>>37
Fucking moron. See >>39 and >>40

Name: Anonymous 2012-01-11 13:31

>>39-41
So you're saying that language is gnu89? The program is still then undefined you fucking retards.

Name: Anonymous 2012-01-11 13:32

41 posts in 40 minutes. What the hell, /prog/.

Name: Anonymous 2012-01-11 13:32

>>42
Just gtfo asspie

Name: Anonymous 2012-01-11 13:32

>>44
Are you angry because your code is shit?

Name: Anonymous 2012-01-11 13:32

>>43
>and no answer to OP
;_;

Name: Anonymous 2012-01-11 13:32

>>46
The answer is undefined you fucking retard are you blind?

Name: Anonymous 2012-01-11 13:33

>>45
Of course it is shit, it is intentionally shit. That is the point. YOU ARE TOO RETARDED TO FIGURE IT OUT.

Name: Anonymous 2012-01-11 13:34

>>48
I have already figured it out you fucking retard, it's UNDEFINED.

Name: Anonymous 2012-01-11 13:35

>>49
facepalm

Name: Anonymous 2012-01-11 13:37

>>49
Not sure if troll, but
>what is the output of this code WHEN COMPILED WITH GCC AND RAN ON AN INTEL ARCHITECTURE
It is kind of implicit in the question.

Name: Anonymous 2012-01-11 13:37

Name: Anonymous 2012-01-11 13:38

>>51
It's still undefined.

Name: Anonymous 2012-01-11 13:39

>>53
Dude. Stop. Just stop.

Name: Anonymous 2012-01-11 13:40

>>53
What the hell is wrong with you dude?

Name: Anonymous 2012-01-11 13:41

>>54,55
There is nothing wrong with me you dumb Jew, what the fuck is wrong with you? How the hell is undefined a hard concept to get?

Name: Anonymous 2012-01-11 13:42

>>56
Confirmed for autistic faggot

Name: Anonymous 2012-01-11 13:43

>>57
You mad that your code is undefined?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 13:43

And you all think that I'm out of control....

Name: Anonymous 2012-01-11 13:44

>>58
The only thing you're accomplishing is to confirm that you aren't clever enough to actually objdump the code and step through it to figure what is going on.

Forever a code monkey. Now go back to your scripting languages.

Name: Anonymous 2012-01-11 13:44

>>59
For all we know, this is you.

Name: Anonymous 2012-01-11 13:45

>>60
How may I objdump something that doesn't compile?

Name: Anonymous 2012-01-11 13:45

>>61
It's not Kodak, I can assure you.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 13:46

>>61
Nah. I don't write like that.

Name: Anonymous 2012-01-11 13:46

>>62
By compiling it with the correct compiler, e.g. one proposed in the comments.

Name: Anonymous 2012-01-11 13:50

>>60
Why wouldn't you just use gdb and step through the source code?

Name: Anonymous 2012-01-11 13:52

>>66
Of course, you could always use gdb. But gdb gets a bit confused when the symbols are stripped and the function is outside the .text section

Name: Anonymous 2012-01-11 13:53

>>67
So why are you stripping the symbols?

Name: Anonymous 2012-01-11 13:54

So this is OS specific, compiler specific, processor specific, compiler flags specific code?

Name: Anonymous 2012-01-11 13:55

>>69
Yep. Not so much OS specific as architecture specific, compiler and compiler specific code though.

Name: Anonymous 2012-01-11 13:56

>>69
Not OS specific, but processor and compiler specific. Yes. Or, actually, to be more correct, processor and assembler specific code.

Name: Anonymous 2012-01-11 13:58

>>52
This.

The first 32 characters of the char data is a swap function. Actually identical to the link, are you copypastaing OP?

Name: Anonymous 2012-01-11 13:59

>>71
So those signals are not OS specific?

Name: Anonymous 2012-01-11 14:01

~/prog$ gcc -o a.out -m32 -O0 -c obscure.c && strings a.out
D$0
D$,1D$<
D$,3D$<
D$,1D$<
goto considered harmfull

Name: Anonymous 2012-01-11 14:01

>>73
No, those are POSIX. You're correct though, but any POSIX OS should be able to run it.

Name: Anonymous 2012-01-11 14:08

>>75
Mac OS X doesn't allow executing the const char * data.

Name: Anonymous 2012-01-11 14:10

>>76
Processor?

Also, does Mac OS X support NX? In that case, it won't run.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:17

>>76
Mac OS X doesn't allow executing the const char * data

Uhh... it this because something like this isn't a value?!!!

Name: Anonymous 2012-01-11 14:18

>>78
Probably because it is put in a read only section with other strings, and OS X doesn't allow readonly sections to be executed.

Name: Anonymous 2012-01-11 14:21

>>79
wat

Name: Anonymous 2012-01-11 14:29

>>39
>>40
The code posted is neither: C,C++,Ada,Fortan nor Java

Please go back to the imageboards you uneducated pieces of shit.

Please learn what the word `undefined' means.
Please learn what reserved keywords mean.
`

Name: Anonymous 2012-01-11 14:30

>>81
>reserved keyword
That is exactly what it is for. Inline assembly. You are so god damned retarded it hurts.

Name: Anonymous 2012-01-11 14:31

>>81
Are you back again?

Name: Anonymous 2012-01-11 14:32

>>81
>hurr wuts assembly durrrrr

Name: Anonymous 2012-01-11 14:33

>>82-84
Why are you samefagging so much?

Name: Anonymous 2012-01-11 14:35

>>82
>>83
>>84
Enjoying your non-standard, unportable, undefined code that's shit?

I hope you do realize this code is as it says: `undefined'. The output is not guaranteed to be the same for all people. Can you comprehend that simple statement?

Name: Anonymous 2012-01-11 14:37

>>86
>same compiler on Intel architecture
Its not going to be different, retard

Name: Anonymous 2012-01-11 14:37

>>86
No they can't, I have tried.
I'm the person he thinks you are now.

Just ask them show you where __asm is defined in any of the C standards.

Name: Anonymous 2012-01-11 14:37

>>86-87
samefag samefagging samefag

Name: Anonymous 2012-01-11 14:38

>>87
There is no way you can guarantee that, that is due to the undefined behavior.

Name: Anonymous 2012-01-11 14:39

>>87-88
For fuck sake, why do you think it is reserved? That's right, to inline assembly. God you are retarded.

Name: Anonymous 2012-01-11 14:39

OP, just go back to /g/.

Name: Anonymous 2012-01-11 14:40

>>90
There is. Same compiler for same architecture will produce same machine code -> same result. It isn't undefined behaviour. __asm doesn't result in undefined behaviour you fucking moron, __asm inlines assembly.

Name: Anonymous 2012-01-11 14:41

>>87
HURR DURR WE ALL HAVE INTELS AND THE SAME PROCESSOR. HOW DO I PORTABLE CODE.
>>88
see >>74
Your code is undefined, stop acting as if it's not.
Some people can't even compile your code even with the commands you give because it is not standard.

Name: Anonymous 2012-01-11 14:41

>>91
Read the standard you fucking retard. Any identifier that starts with two leading underscores is reserved, there is nothing in the standard that defines what __asm does or even mentions assembly.
__asm isn't part of C you fucking moron now fuck off back to /g/ with your retarded shit.

Name: Anonymous 2012-01-11 14:42

FIGHT FIGHT

Name: Anonymous 2012-01-11 14:43

K&R The C programming language, 2ed page 192. (apendix A)

The following identifiers are reserved for use as keywords (AS keywords[sic!]), and may not be used otherwise: [...]
Some implementations reserve the words fortran and asm.

It means that they ARE keywords. Which is VALID code, for some implementations of C. God you are retarded. Go back to scripting.

Name: Anonymous 2012-01-11 14:43

>>93
You don't understand, if it's undefined then you can't guarantee that it will produce the same code every time.

Name: Anonymous 2012-01-11 14:44

>>97
Which is VALID code, for some implementations of C.

YOU ENJOYING THAT UNDEFINED BEHAVIOR?

Name: Anonymous 2012-01-11 14:44

Name: Anonymous 2012-01-11 14:45

>>99
USE THE COMPILER IN OP. God how autistic are you?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:45

>>95
I just searched for the phrase "__asm" in ANSI/ISO C9899. Do you know many matches I found? None. Zip. Zero.

Name: Anonymous 2012-01-11 14:45

>>97
[quote]Some implementations reserve the words fortran and asm.
[/quote]

__asm != asm

Name: Anonymous 2012-01-11 14:45

>>100
Still isn't valid C code you dumb shit.

Name: Anonymous 2012-01-11 14:46

>>98
Of course you can.

Name: Anonymous 2012-01-11 14:46

>>100
asm, __asm__
__asm is not defined in that article, try again.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 14:47

Hey genius, did you notice the part of the doc that read "C extensions"? In other words, it's an extension of standard C.

Name: Anonymous 2012-01-11 14:48

>>101
USE THE COMPILER IN OP. God how autistic are you?

I don't use non-standard compilers.

Please take your shitty toy language subset of C back to the imageboards you dumb fuck.

Next time you come to /prog/ expecting us to do something for you don't fucking make obscure code that requires the download of a non-standard tool, We are not fucking hipsters that act like hackers all day by using undefined shitty code.

Name: Anonymous 2012-01-11 14:49

>>105
You can guarantee that GCC won't rely on undefined behavior to compile undefined behavior?

Name: Anonymous 2012-01-11 14:50

>>108
| I don't use non-standard compilers.

So why are you even replying?

| Please take your shitty toy language subset of C

herp derp

| that requires the download of a non-standard tool

GCC is non-standard, wow. Just wow.

Name: Anonymous 2012-01-11 14:51

>>107
I never claimed it to be non-standard. But the faggots here are all herp derp its non-standard derp instead of just not responding. Fucking obsessive-compulsive disorder

Name: Anonymous 2012-01-11 14:52

>can't add/remove __
>go apeshit insane
Fucking /prog/

Name: Anonymous 2012-01-11 14:53

>>100
This does not define __asm, it only defines asm and __asm__.

Name: Anonymous 2012-01-11 14:53

>>110
You think gnu89 which is the default for Gcc is standard now?
You think GCC extensions are standard?

Name: Anonymous 2012-01-11 14:56

>>113
Beyond this, even if __asm was asm in your example your usage of it is undefined as it has side effects.

Name: Anonymous 2012-01-11 14:56

>>114
I'm telling you to use gcc for fuck sake. And you wont, so okay. GTFO then.

Name: Anonymous 2012-01-11 14:59


[ Wed Jan 11 02:52:07 ]
[ @ ~/fhost/prog/C ] $ cat nstd.c
// tested with Core 2 Duo, Core 2 Quad and Xeon
// tested with gcc4.1.2 gcc4.4.3 and gcc4.6.1
// compile with: gcc -O0 -m32
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>

jmp_buf p;
void (*q)();

const char *data =
    "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
    "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
    "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
    "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
    "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
    "\x55\x90\x90\x89\xe5\x90\x90\x90"
    "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
    "\x60\x09\x0e\x13\x14\x01\x0c\x0c"
    "\xc0\x07\x05\x0e\x14\x0f\x0f\x60"
    "\x00\x67\x6f\x74\x6f\x20\x63\x6f"
    "\x6e\x73\x69\x64\x65\x72\x65\x64"
    "\x20\x68\x61\x72\x6d\x66\x75\x6c"
    "\x6c\x00\x90\x90\x1c\x1b\x0a\x20";

int f(int x)
{
    static int b = 0; static int s = 0;
    int a = 0, t;
    if (!s) {
        a = b; b = x;
    } else {
        a = x; t = b;
        do {
            a ^= b;
            b = (a^b) & b;
            b <<= 1;
        } while (b);
        b = t;
    }
    s = (s+1) % 2;
    return a;
}

int g(int i, int *j)
{
    *j = i;
    i = (int) putchar;
    if (*j == (48 << 1))
        __asm volatile (
                "movl 8(%ebp),%eax;"
                "leave;"
                "ret"
                                        );
    return (int) puts;
}

void h(int i)
{
    int b;
    q = (void(*)()) g(i++[data],&b);
    for (f(b);*(data+i)!=b;++i,f(b))
        q(f(i[data])%0xff);
}

void sh(int s)
{
    if (s == 010)
        ((void(*)())g(s,&s))("F");
    longjmp(p,s);
}

int main(void)
{
    int base, addr = 0xffffffff, offs = 16;
    int a = 11, b = 32, i = 25;
    int s = 8, t = 1, u = 4;
    ((void(*)()) data)(&a,&b);
    ((void(*)()) data)(&b,&t);
    ((void(*)()) data)(&t,&s);
    addr ^= a;
    a ^= addr;
    addr ^= a;
    base = ((int(*)())data+addr)();
    if (a == -1)
        goto over;
    puts("A");

    base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
    h(base+addr+offs);
    exit(0);

 over:
    signal(t,sh);signal(s,sh);signal(u,sh);

    if (!(s = setjmp(p))) {
        q = (void(*)()) g(0x30, &a);
        q(data + a + i);
        s = a / (b-1);
        puts("B");
    } else if (s == 0xb) {
        puts("C");
        ((int(*)(int)) data+addr+(offs/2))(base);
    } else {
        puts("D");
        *((int*) base+s) = 0xffffffff;
    }
  
    puts("E");
    return 1;
}
[ Wed Jan 11 02:52:09 ]
[ @ ~/fhost/prog/C ] $ gcc -O0 -m32 nstd.c
nstd.c: In function ‘g’:
nstd.c:49: warning: cast from pointer to integer of different size
nstd.c:56: warning: cast from pointer to integer of different size
nstd.c: In function ‘h’:
nstd.c:62: warning: cast to pointer from integer of different size
nstd.c: In function ‘sh’:
nstd.c:70: warning: cast to pointer from integer of different size
nstd.c: In function ‘main’:
nstd.c:98: warning: cast to pointer from integer of different size
nstd.c:107: warning: cast to pointer from integer of different size
[ Wed Jan 11 02:55:03 ]
[ @ ~/fhost/prog/C ] $ ./a.out
Segmentation fault



SEGMENTATION FAULT

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 15:02

>>117
And the truth shall set you free...

Name: Anonymous 2012-01-11 15:02

Dirty dumb non-standard scum.

Name: Anonymous 2012-01-11 15:02

>>117
| -m32
| cast from pointer to integer of different size

Yeah, no. 0 / 10 trolling attempt

Name: Anonymous 2012-01-11 15:03

>>117
-m32 shouldn't produce those cast to x of different size...

Name: Anonymous 2012-01-11 15:06

/g/ quality thread.

Name: Anonymous 2012-01-11 15:06

Just leave and go back to /g/.

Name: Anonymous 2012-01-11 15:08

>>120-121
Agreed, >>117 is clearly doing something wrong. -m32 sets 32-bit environment, ints, longs and pointers to 32-bit

Name: 0|\ 1999 2012-01-11 15:10

HEY GUISSE WHAT IS DE OUTPUT OF THIS PROGREM?

#include <stdio.h>

int main (void) {
  int a;

  printf("%d\n", a);

  return 0;
}


ALL MUST COMPILE WITH GCC AND ONLY USE ON INTEL PROCESSORS, SINCE IT'S THE SAME COMPILER AND SAME PROCESSOR IT WILL ALWAYS PRODUCE THE SAME OUTPUT

thANKS FOR lISTENING!

Name: Anonymous 2012-01-11 15:11

>>117
Do:
gcc -m32 -O0 nstd.c && readelf -h a.out

Name: Anonymous 2012-01-11 15:12

>>125
Except OPs code is not undefined at all.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 15:14

>>125
It will compile, but the output is undefined.

Name: 3c14|_ 2012-01-11 15:14

>>127
YEAH DATS WUT I SED LOL
I FORGOT TO TELL THOUGH ALL MUST COMPILE WITH -O0 AND -m32 OR ELSE IT WON'T WORK thANKS FOR lISTENING IF YOU USE THIS FLAGS IT WILL ALWAYS PRODUCE THE SAME CODE SO IT WILL ALWAYS GIVE THE SAME RESULT

Name: Anonymous 2012-01-11 15:15

>>129
In ops case it always will, unless your OS is NX capable in which things will break.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 15:16

>>125
But having 'int a' as a global variable isn't a semantic error. Yeah, I know it's gay. But like everyone else, I don't write the rules, I just play by them.

Name: Anonymous 2012-01-11 15:16

>>129
>implying inline assembly is as undefined as uninitialized variables

Name: 3c14|_ 3|)Uc4t10n 2012-01-11 15:16

>>130
YEAH DATS WUT I SED ARE U HAVING TRUBLE READING?

Name: Anonymous 2012-01-11 15:17

ITT: Inline assembly is undefined behaviour

Name: T01l33t $R(_)|3|3Er 2012-01-11 15:19

>>128
BUT HOW IS DAT POSIBEL? IT WILL ALWAYS CREATE THE SAME CODE AND RUN ON THE SAME PROCESSORS??????

Name: Anonymous 2012-01-11 15:21

>>134
If you read the GNU extension page the usage of the __asm in OP is undefined in GNU-C as well since it has extraordinary side-effects such as altering the stack which GCC assumes it doesn't for performance reasons.

Name: Anonymous 2012-01-11 15:23

>>135
PLEASE STOP FAGGING UP MY 4CHAN EXPERIENCE. THANK YOU.

Name: Anonymous 2012-01-11 15:23

>>136
I'm guessing that's why -O0 was included

Name: Anonymous 2012-01-11 15:24

>>138
It doesn't matter, it's undefined GNU-C, you can't tell what it does.

Name: A3R (_) A $(_)|3$Et 2012-01-11 15:26

>>137
OKAY SORI

Name: Anonymous 2012-01-11 15:27

>>137
This isn't 4chan.

Name: Anonymous 2012-01-11 15:27

uname -r && (cat /proc/cpuinfo | grep "model name" -m 1) && (gcc --version | grep gcc) && gcc -m32 -O0 test.c && ./a.out
3.0.0-14-generic
model name    : Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
goto considered harmfull
F
D
C
A
install gentoo

$ uname -r && (cat /proc/cpuinfo | grep "model name" -m 1) && (gcc --version | grep gcc) && gcc -m32 -O0 test.c && ./a.out
2.6.18-274.el5
model name      : Intel(R) Xeon(R) CPU           L7555  @ 1.87GHz
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51)
goto considered harmfull
F
D
C
A
install gentoo

uname -r && (cat /proc/cpuinfo | grep "model name" -m 1) && (gcc --version | grep gcc) && gcc -m32 -O0 test.c && ./a.out
2.6.32-36-generic
model name    : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz
gcc-4.4.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3
goto considered harmfull
F
D
C
A
install gentoo

uname -r && (cat /proc/cpuinfo | grep "model name" -m 1) && (gcc --version | grep gcc) && gcc -m32 -O0 test.c && ./a.out
2.6.32-37-generic
model name    : AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
goto considered harmfull
F
D
C
A

Name: Alpha Male !gD3Op2fhHs 2012-01-11 15:28

Hey brah it's spelled harmful and not harmfull.

Name: Anonymous 2012-01-11 15:29

>>142
forgot last line, says install gentoo as well

Name: Anonymous 2012-01-11 15:29

>>142
That doesn't matter you dumb Jew, it's still undefined, you can't guarantee that it'll always output that.

Name: Anonymous 2012-01-11 15:31

ITT people from from /g/ don't understand what undefined means

Name: Anonymous 2012-01-11 15:31

>>143
It's full of harm. Like this thread.

Name: Anonymous 2012-01-11 15:31

# ./a.out
[1]   Illegal instruction (core dumped) ./a.out

Name: Anonymous 2012-01-11 15:32

>>142
It clearly works even on AMD. Fucking morons ITT

Name: Anonymous 2012-01-11 15:33

Who cares if it's undefined in the standard - it's pretty well-defined given a specific compiler+architecture. It can be understood if one is willing to use a disassembler or a debugger.

Not that I'm willing to bother wasting 10 minutes to understand what the code does as as far as I can tell, it just prints some characters in an obfuscated unportable manner, which can be done much easily in a portable manner, here's the disassembly for the data:

8B4424 04       MOV EAX,DWORD PTR SS:[ESP+4]
8B5C24 08       MOV EBX,DWORD PTR SS:[ESP+8]
8B00            MOV EAX,DWORD PTR DS:[EAX]
8B1B            MOV EBX,DWORD PTR DS:[EBX]
31C3            XOR EBX,EAX
31D8            XOR EAX,EBX
31C3            XOR EBX,EAX
8B4C24 04       MOV ECX,DWORD PTR SS:[ESP+4]
8901            MOV DWORD PTR DS:[ECX],EAX
8B4C24 08       MOV ECX,DWORD PTR SS:[ESP+8]
8919            MOV DWORD PTR DS:[ECX],EBX
C3              RETN
90              NOP
55              PUSH EBP
89E5            MOV EBP,ESP
8B45 04         MOV EAX,DWORD PTR SS:[EBP+4]
C9              LEAVE
C3              RETN
55              PUSH EBP
90              NOP
90              NOP
89E5            MOV EBP,ESP
90              NOP
90              NOP
90              NOP
8B45 08         MOV EAX,DWORD PTR SS:[EBP+8]
8945 04         MOV DWORD PTR SS:[EBP+4],EAX
C9              LEAVE
C3              RETN

All this code is too trivial and can be implemented in C without need of asm.

Ends with non-code/data:

60 09 0E 13 14 01 0C 0C C0 07 05 0E 14 0F 0F 60 
00 67 6F 74 6F 20 63 6F 6E 73 69 64 65 72 65 64  .goto considered
20 68 61 72 6D 66 75 6C 6C 00 90 90 1C 1B 0A 20   harmfull


harmfull
Nice english.

Name: Anonymous 2012-01-11 15:33

>>149
Okay then you fucking retard what is the output of >>125?

Name: Anonymous 2012-01-11 15:35

>>129,133,135,140
Funny names.

Name: Anonymous 2012-01-11 15:39

Here OP I fixed your code for you, this is what I think you were trying to do.

#include <stdio.h>

int main (void) {
  puts("goto considered harmfull\n"
       "F\n"
       "D\n"
       "C\n"
       "A\n"
       "install gentoo");

  return 0;
}

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 15:48

>>153
This program will block in it's called to read() on zee *nix box if the underlying device is say, an anonymous pipe -(.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-11 15:51

>>154
So like, the rational solution would be to create a conforming C program. Otherwise, if that's not possible, you have resort to stupid OS specific tricks.

Name: Anonymous 2012-01-11 15:51

``On my machine'' that data string disassembles to this.
   10af3:       46 00 8b        divf2 $0x0 [f-float],(r11)+
   10af6:       44 24 04        mulf2 $0x24 [f-float],$0x4 [f-float]
   10af9:       8b 5c 24 08     bicb3 ap,$0x24,$0x8
   10afd:       8b 00 8b 1b     bicb3 $0x0,(r11)+,$0x1b
   10b01:       31 c3 31        brw 13cc7 <__EH_FRAME_BEGIN__+0x3167>
   10b04:       d8 31 c3 8b     adwc $0x31,0x4c8b(r3)
   10b08:       4c
   10b09:       24 04 89 01     cvtpt $0x4,(r9)+,$0x1,(r11)+,$0x24[ap]
   10b0d:       8b 4c 24
   10b10:       08 89 19 c3     cvtps (r9)+,$0x19,0x5590(r3),(r9)+
   10b14:       90 55 89
   10b17:       e5 8b 45 04     bbcc (r11)+,$0x4[r5],10ae5 <_fini+0x49>
   10b1b:       c9
   10b1c:       c3 55 90 90     subl3 r5,@(r0)+,@(r0)+
   10b20:       89 e5 90 90     bisb3 0x8b909090(r5),$0x8[r5],(r9)+
   10b24:       90 8b 45 08
   10b28:       89
   10b29:       45 04 c9 c3     mulf3 $0x4 [f-float],0x60c3(r9),$0x9 [f-float]
   10b2d:       60 09
   10b2f:       0e 13 14        insque $0x13,$0x14
   10b32:       01              nop
   10b33:       0c 0c c0 07     prober $0xc,0x507(r0),$0xe
   10b37:       05 0e
   10b39:       14 0f           bgtr 10b4a <_fini+0xae>
   10b3b:       0f 60 00        remque (r0),$0x0
   10b3e:       67 6f 74 6f     divd3 (pc),-(r4),(pc)
   10b42:       20 63 6f 6e     addp4 (r3),(pc),(sp),-(r3)
   10b46:       73
   10b47:       69 64 65        cvtdw (r4),(r5)
   10b4a:       72 65 64        mnegd (r5),(r4)
   10b4d:       20 68 61 72     addp4 (r8),(r1),-(r2),(fp)
   10b51:       6d
   10b52:       66 75 6c        divd2 -(r5),(ap)
   10b55:       6c 00 90        cvtbd $0x0,@(r0)+
   10b58:       90 1c 1b        movb $0x1c,$0x1b
   10b5b:       index $0x20,$0x0,Address 0x00010b5e is out of bounds.

Name: Anonymous 2012-01-11 15:54

>>154
Well that doesn't sound very good.

Name: Anonymous 2012-01-11 15:55

>>156
VAX?

Name: Anonymous 2012-01-11 15:57

>>156
Of course it'll disassemble to non-sense in a different architecture than intended was used. Fortunately, there are portable disassemblers for the architecture in question.

Name: Anonymous 2012-01-11 16:57

>>142
Doesn't Lunix have NX?

Name: Anonymous 2012-01-11 17:02

>>154
This program will block in it's called to read()
Nice English.

Name: Anonymous 2012-01-11 17:06

>>160
Not out of the box

Name: Anonymous 2012-01-11 17:10

Wow, all the autism in this thread. OP is clearly a /g/ faggot, but even though the code is ultimately undefined it was in fact a fun puzzle.

Name: Anonymous 2012-01-11 17:12

>>153
That will add an additional new line to the end.

Name: Anonymous 2012-01-11 17:14

Remind me why we rage because of architecture dependent code again?

Name: Anonymous 2012-01-11 17:23

>>161
Don't be j.

Name: Anonymous 2012-01-11 17:24

| Can anyone explain why this program outputs what it does
| HURR DURR OP IT IS UNDEFINED YOUR A FAAGGOTT GB2 GEEEE

Name: Anonymous 2012-01-11 17:32

>>117
>warning: cast from pointer to integer of different size
>gcc -m32

I don't think so Tim.

Name: Anonymous 2012-01-11 17:55

>>162
TERRIBLE!

Name: Anonymous 2012-01-11 20:06

>>165
Because Intel is a Jewish company. If there is any architecture-dependent code, it has to be for a noble architecture like the PDP-anything, VAX, MIPS, or Lisp Machine.

Name: Anonymous 2012-01-11 21:52

>>170
lol dead architectures

Okay, not MIPS, but the rest are. And you didn't mention ARM you fucking gay.

Name: Anonymous 2012-01-11 22:02

>>170
What's noble in the PDP-11 who gave life to C?

Name: Anonymous 2012-01-12 7:15

>>170
| Because Intel is a Jewish company.
Protip: It's not.

Development hq is in jewland though.

Name: Anonymous 2012-01-12 7:36

This thread is why none of you have a real job and spend all day lurking. 10 / 10 OP for provoking /prog/ into a semi-autistic craze.

Name: Anonymous 2012-01-12 7:40

>>174
This thread is why none of you fags from /g/ know how to program properly

Name: Anonymous 2012-01-12 7:44

>>175
You don't get that the code was intentionally backwards? Are you this stupid. Also, not from /g/ but from /sci/ btw.

Name: Anonymous 2012-01-12 7:50

>>176
You don't get that /g/ clearly shows their inability to even know simple terms relating to C nor their ability to know what a compiler does.

You don't get that posting obscure undefined code on /prog/ isn't going to boost your e-peen hax0r creed with us like it would on your hipster imageboards

Name: Anonymous 2012-01-12 7:54

>>177
| your
Try again.

Name: Anonymous 2012-01-12 7:55

>>177
Also, your rage is showing.

Name: Anonymous 2012-01-12 7:59

>>178'
>your hipster imageboards
>your e-peen
>Implying either of those are suppose to be `you are'

You see on the textboards trolls like you fail hard.

>>179
strawmaning.

If you can't stay on topic then go back to your shit imageboards

Name: Anonymous 2012-01-12 8:01

>>180
It wasn't my post, you dumbwit. I'm not OP nor have I commented in this thread before >>176

Also complaining about strawman arguments when you throw strawman after strawman is just ridiculous and shows a complete lack of self-insight.

Name: Anonymous 2012-01-12 8:05

>>181
Pointing out undefined behavior is not a strawman.


If you're not OP and you have no place in this threads discussion other than to try to troll people then please leave. Go back to your shitty imageboards and never come back.

Name: Anonymous 2012-01-12 8:08

>>182
| Pointing out undefined behavior is not a strawman.
I wasn't referring to that. You have no reading comprehension what so ever. I refuse to believe that you are that stupid.

| Go back to your shitty imageboards and never come back.
hurr durr gb2>>>/g/ n00b
herp derp how dare you post strawman fallacies and/or trolls

Jesus, you are unbelievable. Also,
pointing out that you didn't get OP's post != trolling

Name: Anonymous 2012-01-12 8:09

>>182
| If you're not OP and you have no place in this threads discussion other than to try to troll people then please leave.

Now who is throwing strawman arguments into the thread again?

Name: Anonymous 2012-01-12 8:10

>>183
Everyone in this thread understand what OPs post was meant to be: obscure shit code to show off his e-peen.

No one gives a shit about how smart you think you are with your witty comments.

Go back to /sci/ and shit post on there you dumb fucker.

Name: Anonymous 2012-01-12 8:11

>>184
You are, you threw it off topic now get the fuck out if you have nothing good to say that's on topic.

The only thing you fucking shit posters from the imageboards are good at is going off topic and shitty troll attempts.

Name: Anonymous 2012-01-12 8:13

>>185
| obscure shit code to show off his e-peen.
I didn't read it that way, but then again I'm not OP. I was seriously considering to try to trace my way through the code but meh.

| No one gives a shit about how smart you think you are with your witty comments.
Wow, I clearly pushed your buttons. Also, apropos strawman anyone? Just give up, the guy who's always in for the last word, like you're doing now, usually comes off as a dick.

Name: Anonymous 2012-01-12 8:14

>>187
>...to try to trace my way...

Tracing through undefined code? Good one that'll lead you straight to the right answer you dumb fuck.

Name: Anonymous 2012-01-12 8:15

>>182,185-186
All I read from these posts is:
1) Shit posting how dumb OP and other imageboarders is
2) Accusations of off-topic when those accusations being answered
3) More shit posting and off-topic bullshit

Name: Anonymous 2012-01-12 8:18

>>188
Why do you care how I want to spend my time or not, or if I even want to post in this thread and answer OP or not. Just ignore the thread, moron.

Name: Anonymous 2012-01-12 8:18

>>189
*are

Name: Anonymous 2012-01-12 8:20

>>189
All I read from your posts are:
1) You being a dumb fuck
2) You shit posting and acting like we didn't realize it was obscure code to begin with
3) You throwing it off topic

Name: Anonymous 2012-01-12 8:24

>>192
| You shit posting and acting like we didn't realize it was obscure code to begin with
| we
No, all of "us" probably got it. You, on the other hand were more interested in pointing out how stupid OP and everyone is rather than simply ignoring the thread if you thought it was to boost OP's e-peen. That tells me that you probably are a manchild having a hard time accepting that others might do and say stuff you disagree with.

Also, this thread was off-topic as soon as the first guy bashing on OP (most likely you, since you seem to have your feelings hurt) posted.

Name: Anonymous 2012-01-12 8:25

testing
testing

Name: Anonymous 2012-01-12 8:26

The output is undefined.

Name: Anonymous 2012-01-12 8:28

>>193
first guy bashing OP
For posting undefined code and expecting us to tell him the output when the OP clearly knew what the output of his code was? That sure sounds like a good reason for people in this thread to call him a moron and an idiot.

If you couldn't comprehend the fact that the code was obscure shit with undefined uses then you need to go back to learning how to program and stop wasting your time here.

Name: Anonymous 2012-01-12 8:30

>>196
| For posting undefined code and expecting us to tell him the output
Are you this blind? OP clearly says
| Can somebody explain why this code outputs what it does?
>WHY

| If you couldn't comprehend the fact that the code was obscure shit with undefined uses
I do, but on the specified architectures it gives the same output. You, on the otherhand, aren't at all interested and dismiss everything that you don't bother to do as a waste of time. Of course the program relies on undefined behavior, that's what makes it "tricky" to figure out.

Name: Anonymous 2012-01-12 8:32

>>197
The question of what the code outputs is not a well defined question since the output of program is undefined.

The program might as well crash as output something, and when it does output there is no telling what it outputs as it still undefined.

Name: Anonymous 2012-01-12 8:33

>>196
Also, since you are willing to go there:
architecture dependent != undefined behavior
undefined behavior == non-deterministic behavior

Name: Anonymous 2012-01-12 8:35

>>198
See >>142. It's not producing different output.

Name: Anonymous 2012-01-12 8:37

>>199
architecture dependent != undefined behavior
This is incorrect, read the standard.
undefined behavior == non-deterministic behavior
Whether this is correct or not is undefined, read the standard.

You must understand, the program in OP features both undefined behavior in the form of architecture (compiler, compiler flag, OS) dependencies and undefined behavior in the form of non-determinism.

Name: Anonymous 2012-01-12 8:38

>>200
The nature of undefined behavior is such that you can never guarantee that it will always produce the same output.

If you run the program in >>125 it too will probably output the same values a couple of times, but it's equally likely to not output the same value.

Name: Anonymous 2012-01-12 8:39

>>201
| the program in OP features both undefined behavior in the form of architecture (compiler, compiler flag, OS)
True

| and undefined behavior in the form of non-determinism.
How?

Name: Anonymous 2012-01-12 8:43

>>203
Or more precisely, where?

Name: Anonymous 2012-01-12 8:43

>>203
True
Then the programs output is undefined.

How?
If you want to know some of the C violations just compile it with -pedantic, that will tell you about most of them.

Name: Anonymous 2012-01-12 8:45

>>202
Youre retarded i ran the program in >>125 five times and it output 10739700 every single time.

u mad

Name: Anonymous 2012-01-12 8:46

>>205
| Then the programs output is undefined.
But OP specified it to "when ran on the proper architecture". So dismissing it entirely as non-deterministic is simply over-simplifying it. As I said, architecture dependent code does not imply non-deterministic behavior.

| If you want to know some of the C violations just compile it with -pedantic, that will tell you about most of them.
Yes I know, but he also never claimed it to be proper C anyway, in which case he wouldn't have mixed in inline assembly or running machine code.

Name: Anonymous 2012-01-12 8:47

>>206
Hello OP

Name: Anonymous 2012-01-12 8:48

>>205
>>207 continued
Any compiled binary will in that case be non-deterministic, if we follow your logic.

Name: Anonymous 2012-01-12 8:54

>>207
But OP specified it to "when ran on the proper architecture". So dismissing it entirely as non-deterministic is simply over-simplifying it. As I said, architecture dependent code does not imply non-deterministic behavior.
It doesn't imply anything beyond that of being undefined, which means that you can't guarantee that it's deterministic or non-deterministic, especially since GCC is allowed to do anything it wants you can't guarantee that GCC doesn't use undefined behavior to compile it, so that it will sometimes compile to the same program and other times it won't.

Yes I know, but he also never claimed it to be proper C anyway, in which case he wouldn't have mixed in inline assembly or running machine code.
Compiling with -pedantic won't point out the use of __asm since that is valid gnu89. The things that it does point out however is the use of undefined procedures like conversion between object types and function pointer types and arithmetic involving function pointer types.

But even if this was an extended C which had a stack, had __asm and where you were allowed to do conversion between object types and function pointer types and you could do arithmetic involving function pointer types the use of __asm leaves the program undefined as the GCC page specifically states that significant side-effects (like alteration of the stack as in the example) causes undefined behavior.

No matter how twist and turn this will you able to guarantee that the program will output the same thing no matter how many compiler flags you're using, you can't even guarantee that it will compile to the same program.

Name: Anonymous 2012-01-12 8:57

>>209
Any compiled binary will in that case be non-deterministic, if we follow your logic.
This is incorrect.

Name: Anonymous 2012-01-12 9:03

>>210
| so that it will sometimes compile to the same program and other times it won't
wat

| you can't even guarantee that it will compile to the same program.
wat

This is becoming ridiculous. I'm guessing that you are a Lisp programmer of heart. Either that or a mathematician fixated on definitions.

| It doesn't imply anything beyond that of being undefined, which means that you can't guarantee that it's deterministic or non-deterministic, especially since GCC is allowed to do anything it wants you can't guarantee that GCC doesn't use undefined behavior to compile it, so that it will sometimes compile to the same program and other times it won't.
Circular logic.

1. The program is undefined (assumption)
2. GCC uses undefined behavior to compile it because of 1.
3. Therefore, 1 is true.

That is just, pardon my french, bullshit.

| __asm leaves the program undefined as the GCC page specifically states that significant side-effects (like alteration of the stack as in the example) causes undefined behavior.
But so does longjmp, therefore longjmp must also be undefined behavior, right?

Name: Anonymous 2012-01-12 9:06

>>211
But you (or the guy I was responding to) pointed out in >>201 and >>205 that architecture dependent code is undefined/non-deterministic. This means that every binary, which most certainly IS architecture dependent, also must be undefined/non-deterministic if one is to follow that logic.

As you see, clearly that is a contradiction. Thus, architecture dependent code does not at all imply undefined/non-deterministic behaviour.

To be clear: In this case undefined/non-deterministic doesn't mean both, it depends on what you mean.

Name: Anonymous 2012-01-12 9:09

longjmp also alters the stack...

Name: Anonymous 2012-01-12 9:09

>>212
This is becoming ridiculous. I'm guessing that you are a Lisp programmer of heart. Either that or a mathematician fixated on definitions.
Prove to me that GCC doesn't rely on undefined behavior to compile undefined behavior and I'll believe that the source code compiles to same executable every time, the fact is that you can't guarantee that because GCC is allowed to whatever it wants with undefined behavior, you can however review the source code of GCC and find that there is no undefined behavior in the way that it handles undefined behavior in the source of programs that it compiles, in which case you can guarantee that the program will compile to the same executable every time.

1. The program is undefined (assumption)
I have proven that.
2. GCC uses undefined behavior to compile it because of 1.
No I said you can't guarantee that it doesn't, so it might use undefined behavior to compile it.
3. Therefore, 1 is true.
No, you are mixing the source code of the program with the executable it is turned into.

But so does longjmp, therefore longjmp must also be undefined behavior, right?
No longjmp and setjmp are well defined, you might use them to cause undefined behavior but you may also use them in a manner that guarantees there is no undefined behavior.

Name: Anonymous 2012-01-12 9:12

>>215
So how again does the __asm clause alter the stack in a undefined way?

Name: Anonymous 2012-01-12 9:13

>>213
You are mixing the source code of the program with the program it compiles to.

>>214
C has no concept of "the stack" but it has a concept of longjmp, so therefore it is impossible for longjmp as defined by the C standard to behave in such a way that it alters the stack. Read the standard.

Name: Anonymous 2012-01-12 9:14

>>216
Because all the inline assembly does is moving the address of putchar into eax and then returning. In other words, the function returns a function pointer.

Name: Anonymous 2012-01-12 9:16

>>216
It uses the leave instruction.

Name: Anonymous 2012-01-12 9:16

>>212
I'm not >>1-215, this is my first post in this thread.
But so does longjmp, therefore longjmp must also be undefined behavior, right?
setjmp and longjmp mention no alteration of the stack, setjmp saves the environment in a jmp_buf, longjmp restores the environment saved in the jmp_buf.
They may be implemented as certain alterations of the stack, but that doesn't mean it is the only way to do it. Their behaviour is well-defined.
http://pubs.opengroup.org/onlinepubs/7908799/xsh/longjmp.html
http://pubs.opengroup.org/onlinepubs/7908799/xsh/setjmp.html

Name: Anonymous 2012-01-12 9:16

>>217
No, the premise is clearly that undefined code compiles (using a compiler that may or may not use undefined behavior) into a program with undefined behavior. Correct?

Name: Anonymous 2012-01-12 9:18

>>219
Which restores the stack.

>>220
But in the implementation where they do alter the stack, using the logic applied above means that longjmp must be undefined.

Name: Anonymous 2012-01-12 9:19

>>220
Again C has no concept of the stack, setjmp and longjmp can not alter the stack as there is no stack to alter, read the standard. Those pages are implementation details.

Name: Anonymous 2012-01-12 9:19

>>221 continued
This means that if architecture dependent code is undefined, then any binary must be undefined. That is a contradiction.

Name: Anonymous 2012-01-12 9:21

>>223
| setjmp and longjmp can not alter the stack
This is ridiculous and purely nit-picking from your side.

Name: Anonymous 2012-01-12 9:23

>>222
Which restores the stack.
Of the wrong function.

But in the implementation where they do alter the stack, using the logic applied above means that longjmp must be undefined.
You are wrong on two accounts, the premise was that you may not use __asm to alter the stack, the other premise is that longjmp causes undefined behavior when invoked in such a manner that the standard specifies is not undefined behavior.

>>224
You are still mixing architecture dependent source code with the program the source code compiles to.

Name: Anonymous 2012-01-12 9:24

>>225
What is your point? The standard specifies what behavior is undefined and what behavior isn't undefined, it's clearly in the scope of this discussion.

Name: Anonymous 2012-01-12 9:24

>>226
| Of the wrong function.
No, it does not.

Name: Anonymous 2012-01-12 9:25

>>226-227
But longjump uses __asm__ to alter the stack on many architectures.

Name: Anonymous 2012-01-12 9:26

>>226
| Of the wrong function.
What do you mean? Are you under the assumption that __asm is a function and not a macro?

Name: Anonymous 2012-01-12 9:28

>>228
The second it is called the program is undefined, you are still executing in the function named g when you invalidate the stack and the GNU C extension page explicitly states that it causes undefined behavior to do so.

Name: Anonymous 2012-01-12 9:29

>>231
It doesn't alter the stack other than returning in the same manner the function itself returns.

Name: Anonymous 2012-01-12 9:29

>>230
No it introduces to g the stack context of the callee of g, which is invalid.

>>229
What is your point?

Name: Anonymous 2012-01-12 9:30

>>232
What is your point? The second leave is called from the __asm function the program is undefined, it doesn't matter what instruction comes afterward, GCC might do what you expect it to do and it might not, the point being is that it's undefined.

Name: Anonymous 2012-01-12 9:31

>>233
| No it introduces to g the stack context of the callee of g, which is invalid.
First of all, g is the callee, but assuming you meant caller: No it doesn't, it simply adds a return from one of the variables in g.

| What is your point?
Any implementation of longjmp that alters the stack results in undefined behaviour, applying your logic.

Name: Anonymous 2012-01-12 9:33

why is OP using __asm and not __asm__ or asm?

Name: Anonymous 2012-01-12 9:33

>>234
What is your point? leave does nothing but restore the stack to the state that it was in when g was called, and ret pops the return address from the stack and sets the ip to that value.

If you claim that leave alters the stack, surely ret must do as well.

Name: Anonymous 2012-01-12 9:34

>>236
It doesn't matter. You could use any of those, they are all processed into the same by the preprocessor. Here on /prog/, on the other hand, we tend to overfocus on correctness.

Name: Anonymous 2012-01-12 9:35

>>235
First of all, g is the callee, but assuming you meant caller: No it doesn't, it simply adds a return from one of the variables in g.
You are probably right about the callee/caller. What is still right however is that leave alters the stack such that the program is undefined.

Any implementation of longjmp that alters the stack results in undefined behaviour, applying your logic.
I never claimed that, that's a lie and it's also incorrect. I stated that the use of __asm to alter the stack causes undefined behavior, I also stated that usage of longjmp in a manner defined by the C standard does not yield undefined behavior.

Name: Anonymous 2012-01-12 9:37

>>237
What is your point? leave does nothing but restore the stack to the state that it was in when g was called, and ret pops the return address from the stack and sets the ip to that value.
So you admit that leave alters the stack? Then the program is undefined as it being called from __asm.

Name: Anonymous 2012-01-12 9:37

>>239
[quote]I stated that the use of __asm to alter the stack causes undefined behavior, I also stated that usage of longjmp in a manner defined by the C standard does not yield undefined behavior.[/quote]

That is contradicting since the implementation of longjmp on my machine most certainly uses __asm__ to alter the stack.

Name: Anonymous 2012-01-12 9:38

>>240
BUT SO DOES LONGJMP

Name: Anonymous 2012-01-12 9:42

>>242
longjmp has no concept of the stack, read the standard.

Name: Anonymous 2012-01-12 9:45

>>243
standard schmandard

The implementation of setjmp and longjmp clearly does.

Name: Anonymous 2012-01-12 9:46

>>241
Under the assumptions that longjmp on your machine is implemented using __asm__ in GCC I will agree that logic dictates that the __asm__ that is used to implement longjmp is well defined on your machine as long as it is only used exactly like longjmp is defined to work in the standard, any other usage is still undefined.

Name: Anonymous 2012-01-12 9:47

>>244
The implementation of setjmp and longjmp clearly does.
That is nonsensical, what if I have an architecture without a stack?

>>241,245
By the way I would very much like to see the implementation of longjmp on your machine.

Name: 246 2012-01-12 9:50

I am going to go away now as I have obligations, I will probably be back in a couple of hours and I'd be happy to continue our debate.

Name: Anonymous 2012-01-12 9:52

>>246
| That is nonsensical, what if I have an architecture without a stack?
On the architectures proposed by OP, silly.

The definition itself is: longjmp, siglongjmp - nonlocal jump to a saved stack context

Name: Anonymous 2012-01-12 9:56

>>248
Your edition of the standard seems to be erroneous, on mine it says setjmp - saves the calling environment, longjmp - restores calling environment while siglongjmp is not defined and I can't find it in C89, C99 or C11.

Name: not >>246 2012-01-12 9:58

>>248
The definition itself is: longjmp, siglongjmp - nonlocal jump to a saved stack context
    setjmp - set jump point for a non-local goto
    longjmp - non-local goto
I don't see any ``stack'' here.

Name: Anonymous 2012-01-12 10:04


$ man longjmp > bla.txt
$ cat bla.txt
LONGJMP(3)                                               Linux Programmer's Manual                                              LONGJMP(3)



NAME
       longjmp, siglongjmp - nonlocal jump to a saved stack context

SYNOPSIS
       #include <setjmp.h>

       void longjmp(jmp_buf env, int val);

       void siglongjmp(sigjmp_buf env, int val);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       siglongjmp(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_C_SOURCE

DESCRIPTION
       longjmp()  and  setjmp(3)  are  useful  for  dealing with errors and interrupts encountered in a low-level subroutine of a program.
       longjmp() restores the environment saved by the last call of setjmp(3) with the corresponding env  argument.   After  longjmp()  is
       completed, program execution continues as if the corresponding call of setjmp(3) had just returned the value val.  longjmp() cannot
       cause 0 to be returned.  If longjmp() is invoked with a second argument of 0, 1 will be returned instead.

       siglongjmp() is similar to longjmp() except for the type of its env argument.  If, and only if, the sigsetjmp(3) call that set this
       env used a nonzero savesigs flag, siglongjmp() also restores the signal mask that was saved by sigsetjmp(3).

RETURN VALUE
       These functions never return.

CONFORMING TO
       C89, C99, and POSIX.1-2001 specify longjmp().  POSIX.1-2001 specifies siglongjmp().

NOTES
       POSIX  does  not  specify  whether longjmp() will restore the signal context (see setjmp(3) for some more details).  If you want to
       portably save and restore signal masks, use sigsetjmp() and siglongjmp().

       The values of automatic variables are unspecified after a call to longjmp() if they meet all the following criteria:

       ·  they are local to the function that made the corresponding setjmp(3) call;

       ·  their values are changed between the calls to setjmp(3) and longjmp(); and

       ·  they are not declared as volatile.

       Analogous remarks apply for siglongjmp().

       longjmp() and siglongjmp() make programs hard to understand and maintain.  If possible an alternative should be used.

SEE ALSO
       setjmp(3), sigsetjmp(3)

COLOPHON
       This page is part of release 3.27 of the Linux man-pages project.  A description of the project, and  information  about  reporting
       bugs, can be found at http://www.kernel.org/doc/man-pages/.



                                                                2009-01-13                                                      LONGJMP(3)

Name: Anonymous 2012-01-12 10:06

>>251
Of course, it's not "the standard".

Name: Anonymous 2012-01-12 10:10

>>251
Linux Programmer's Manual

[b][i][o]
LINUX IS NOT THE STANDARD
[/b][/i][/o]

Name: Anonymous 2012-01-12 10:10

>>251-252
the man pages are implementation details

Name: Anonymous 2012-01-12 10:15

>>254
Yes, but wasn't that the point? If the implementation of longjmp alters the stack than that would inherently be considered undefined.

Name: Anonymous 2012-01-12 10:16

>>254
FOR LINUX

Name: Anonymous 2012-01-12 10:17

>>256
Which doesn't contradict OP

Name: Anonymous 2012-01-12 10:20

>>254
That was my point.

Name: Anonymous 2012-01-12 10:38

>>117
You didn't really use -m32 there, did you

Name: Anonymous 2012-01-12 10:46

>>259
It was a troll obviously.

Name: Anonymous 2012-01-12 10:47

Aaand thread of the year award goes to this thread.

Guys, you can stop posting now. All of you. It's ok.

Name: Anonymous 2012-01-12 11:02

>>255
He explicitly stated that wasn't what he said and that it's untrue if you read >>239,245. You're being willfully ignorant about it, I'm not going bother to argue with you like he does, I would never have the patience to it, but I'm going to tell you that you're acting like a child.

Name: Anonymous 2012-01-12 11:04

By the way the program is undefined so the output is undefined.

Name: Anonymous 2012-01-12 11:14

>>263
You just keep on telling yourself that.

Name: Anonymous 2012-01-12 11:15

>>238
The preprocessor doesn't do anything to __asm, __asm__ or asm, do you even know what the preprocessor is?
And you have yet to show where __asm is defined as the doc linked to in >>100 doesn't even mention it.

Name: Anonymous 2012-01-12 11:17

>>264
Where is __asm defined then you fucking retard? What happens when you convert between data pointers and function pointers then you fucking retard? What happens when you do arithmetic with function pointers then you fucking retard?

Name: Anonymous 2012-01-12 11:20

>>262
You're missing the point. The point is that setjmp does in fact alter the stack by pushing registers, flags and calling environment and longjmp pushes that data from the stack, alters the return address and jumps.

Name: Anonymous 2012-01-12 11:22

>>266
What happens when you do arithmetic with function pointers then you fucking retard?

hurr durr pointer arithmetics are undefined behaviour

Name: /prog/ police !1fOeGamQwA!PrM413+Y2UUOlKE 2012-01-12 11:24

/g/ quality thread.

Name: Anonymous 2012-01-12 11:26

>>268
This is true in the case of void pointers and function pointers you dumb Jew. Fuck off back to /g/ until you have at least read one of the fucking standards you dumb piece of shit.

Name: Anonymous 2012-01-12 11:28

ITT
| Can somebody explain why this code outputs what it does?
| hurf durf show your ePenis somewhere else, it's undefined go fuck yourself nerf

Name: Anonymous 2012-01-12 11:28

>>267
There are safe constructs that alter the stack you dumb piece of shit, have you ever of "return" you god damned retard? longjmp is another way of safely altering the stack. Altering it from asm is unsafe and it says so at the fucking GCC page, what kind of mental disability do you have because you must have negative IQ or something.

Name: Anonymous 2012-01-12 11:31

>>271
The original question was answered in the first couple of posts, it either outputs Segmentation fault, the output >>142 or doesn't compile at all. Why you ask? Because it's undefined.

Name: Anonymous 2012-01-12 11:31

>>270
| This is true in the case of void pointers and function pointers
Can't into array of function pointers.

Name: Anonymous 2012-01-12 11:32

>>272
HOW DO YOU THINK LONGJMP IS IMPLEMENTED, fucking moron...

Name: Anonymous 2012-01-12 11:33

>>274
Read the standard you dumb piece of shit.

Name: Anonymous 2012-01-12 11:36

>>275
I think it's implemented safely unlike the fucking retarded shit that's posted in >>1, are you seriously this fucking dense? Why would the GCC manuals explicitly state that it's bad and dangerous to alter the stack through asm? Because your monkey ass is so fucking dumb that you might do something retarded like what was posted in >>1. And please you fucking retard, show us the source code of longjmp and setjmp on your system you dumb piece of shit, come up with some fucking evidence before you talk again.

Name: Anonymous 2012-01-12 11:41

>>277
Bad and dangerous != undefined behaviour

Name: Anonymous 2012-01-12 11:43

>>276
Not that guy, but an array of function pointers aren't non-standard...

Name: /V\3|\|T4|_ /V\1|)G3T 2012-01-12 11:48

>>277
LMAO U GAY AND JELY RUN THIS PICE OF CODE U ASSMASETR DIS CODE IS 100% SAFE BUT MUST COMPILE WITH -m32 KAY???+

#include <stdio.h>

int main (void) {
  int a = 2;
  int b = 3;
  int c = 5;

  asm("add 8(%ebp), %esp");

  printf("%d\n", b);

  return 0;
}

Name: Anonymous 2012-01-12 11:49

>>279
But arithmetic with function pointers are.

Name: Anonymous 2012-01-12 11:54

>>280
OP never claimed it to be safe, nor to work on any architecture.

Name: Anonymous 2012-01-12 11:56

>>282
Well if it doesn't work on any architecture why are we having this discussion? If it doesn't work on any architecture then the program obviously doesn't output anything and the reason why is because it doesn't work on any architecture.

Name: Anonymous 2012-01-12 12:02

>>283
But it does work on some architectures... How hard is that to grasp, exactly?

Name: Anonymous 2012-01-12 12:02

>>284
But it does work on some architectures
You can't guarantee that.

Name: Anonymous 2012-01-12 12:07

>>281
Are you sure about that?

Name: Anonymous 2012-01-12 12:09

>>285
It as simple as this, if it doesn't compile or it segfaults then don't bother answering in this thread. If it does compile and works, try to provide a program flow for OP. How is this hard to understand?

Also, see >>142

Name: Anonymous 2012-01-12 12:10

>>284
How hard is it to grasp the concept of undefined behavior?

Name: Anonymous 2012-01-12 12:10

>>286
If you want to prove me wrong feel free to show me where in the standard it says that it's allowed to do arithmetic on function pointer types.

Name: Anonymous 2012-01-12 12:12

>>287
Compile the program in >>125 and tell me what it outputs, perhaps that will help you realize that running a programming 4 times doesn't necessarily tell you much about it.

Name: Anonymous 2012-01-12 12:16

>>270,276,281
I guess it depends on which standard you use. Arithmetics with void pointers are generally considered non-standard, but function pointer arithmetics are considered standard.

Name: Anonymous 2012-01-12 12:18

>>288,290
And how hard is it to grasp that that piece of code isn't relying on undefined behavior, but the underlaying architecture.

Name: Anonymous 2012-01-12 12:35

>>289
| function pointer arithmetics aren't allowed but array of function pointers is
I think you need to think before you write.

Name: Anonymous 2012-01-12 12:41

I will only run ENTERPRISE QUALITY code in my machine

Name: Anonymous 2012-01-12 12:52

>>293
fp is a function pointer, fp[1]() is undefined.
fpa is an array of function pointers, fpa[1]() is defined, fpa[1][1]() is undefined.

Name: Anonymous 2012-01-12 12:55

>>295
I'm not sure if we're talking about the same thing now, but I don't see how (*(fpa+1))() wouldn't be allowed, while fpa[1]() would.

Name: Anonymous 2012-01-12 12:57

Next, we discuss #pragmas.

Name: Anonymous 2012-01-12 12:57

>>296
but I don't see how (*(fpa+1))() wouldn't be allowed,
You're still doing pointer arithmetic on an array, it is allowed.

Name: Anonymous 2012-01-12 13:00

>>1-298

Dennis Ritchie is rolling in his grave right now.

Name: Anonymous 2012-01-12 13:00

>>298
Oh, I see where the misunderstanding is now.

Name: Anonymous 2012-01-12 13:55

>>291
Are you fucking retarded you dumb piece of shit? The C standard is obviously the standard in question, where you can't do pointer arithmetic with void pointers and you can't do pointer arithmetic with function pointer types.

Name: Anonymous 2012-01-12 13:56

>>292
It relies on both you fucking moron.

Name: Anonymous 2012-01-12 14:06

you guys are mean... im going back to reddit with my cool programs fuck you

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-12 14:06

>>298
Technically you're not doing pointer arithmetic on an array. Psst....hey toilet scrubber, an array and an element in that array are two different things. One is an unmodifiable lvalue and the other isn't.

Name: VIPPER 2012-01-12 14:07

>>303
Make sure you never come back.

Name: Anonymous 2012-01-12 14:13

>>302
Prove it. No, __asm is considered bad and potentially dangerous, not undefined.

>>301
| The C standard
You know there are multiple standards, moron. You can have an array of functions, you are this retarded.

Name: Anonymous 2012-01-12 14:15

>>306
*function pointers

Name: Anonymous 2012-01-12 14:25

>>306
You know there are multiple standards, moron. You can have an array of functions, you are this retarded.
I said that you can't do arithmetic on function pointers you dumb piece of shit, learn do read you fucking retard.

And please you retarded piece of crap, show me which of the C standards allows arithmetic on function pointers.

Name: Anonymous 2012-01-12 14:27

>>308
Gnu99, amongst others

Name: Anonymous 2012-01-12 14:28

>>309
Hahaha.

Name: Anonymous 2012-01-12 14:29

>>309
You dumb piece of shit, Gnu99 isn't a C standard you fucking retard. Are you seriously this fucking dumb?

Name: Anonymous 2012-01-12 14:30

>>309
GNU is the new standards committee guys, you heard it here first.
Free as in freedom C standards.

Name: Anonymous 2012-01-12 14:32

>>312
I wouldn't mind that, ISO is ran by a bunch of Jews.

Name: Anonymous 2012-01-12 14:40

>>312
Enjoying your bloated freedom at all costs?

Name: Anonymous 2012-01-12 14:44

>>314
He who sacrifices freedom for non-bloatedness deserves Windows.

Name: Anonymous 2012-01-12 14:45

>>315
Windows isn't bloated? Now I've heard everything.

Name: Anonymous 2012-01-12 14:46

>>314
Enjoying your shit performance?

Name: Anonymous 2012-01-12 15:02

>>316
It's less bloated than GUN/Rinux.

Name: Anonymous 2012-01-12 15:10

>>318
Who's talking about Loonix?

Name: Anonymous 2012-01-12 15:29

IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT
IM BETTER THAN U _BECAUSE_ I STAY AT HOME ARGUING ABOUT AUTISTIC ASM SHIT

Name: Anonymous 2012-01-12 15:30

Name: Anonymous 2012-01-12 15:32

>>320
It's not ASM, we're discussing C like grown ups. You should probably go back to playing programmer on /g/

Name: Anonymous 2012-01-12 15:34

>>322
Go back to /g/

Name: /g/ !!QSvwrQMMkoH22b4 2012-01-12 15:39

LMAO INSTALL GENTOO DESKTOP THREAD XD

Name: Anonymous 2012-01-12 15:49

>>320
umad?

Name: Anonymous 2012-01-12 15:53

>>325
no u

Name: Anonymous 2012-01-12 15:55

>>320
You remind me of that kid on /g/ who pretends to be an Arch Linux user

Name: Anonymous 2012-01-12 16:08

>>327
You remind me of that kid on /g/ that pretends to be a professional C programmer

Name: Anonymous 2012-01-12 16:09

>>328
8/10

Name: Anonymous 2012-01-12 16:18

>300 posts in two days, wow

Name: Anonymous 2012-01-12 16:19

>>328
/g/ remind me of that professional you programmer that pretends to be a you

Name: Anonymous 2012-01-12 16:29

>>328
Is that the guy with the name "professional C programmer" who didn't know how to use #define in C?

Name: Anonymous 2012-01-12 16:31

>>332
Yep

Name: Anonymous 2012-01-12 16:33

>>333
Okay.

Name: Anonymous 2012-01-12 16:48

>/prog/ - Autism

Name: Anonymous 2012-01-12 16:55

>>335
/g/ - bithurt

Name: Anonymous 2012-01-12 16:55

>>335`
>implying /g/ doesn't have autism as well

Name: Anonymous 2012-01-12 16:58

>>336
/prog/ seems to be the ones that got their feelings hurt ITT

Name: Anonymous 2012-01-12 16:59

>>336
/g/ - Mental Midgets

Name: Anonymous 2012-01-12 17:00

/prog/ - /g/ Without Images

Name: Anonymous 2012-01-12 17:01

/g/ without images in here

Name: Anonymous 2012-01-12 20:49

/g/ without images = ∅

Name: Anonymous 2012-01-13 21:55

Seriously.

Name: Anonymous 2012-01-13 21:56

>>343
Learn to sage and get back to the imageboards

Name: Anonymous 2012-01-13 21:59

>>344

Guess what? I didn't want to sage.

Name: Anonymous 2012-01-13 22:05

>>345
go back to /g/

Name: Anonymous 2012-01-13 22:35

>>1-6 '
>inb4 it relies on unsafe code
>inb4 it relies on undefined behaviour
>inb4 autism



const char *data =
        "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
        "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
        "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
        "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
        "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
        "\x55\x90\x90\x89\xe5\x90\x90\x90"
        "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
        "\x60\x09\x0e\x13\x14\x01\x0c\x0c"
        "\xc0\x07\x05\x0e\x14\x0f\x0f\x60"
        "\x00\x67\x6f\x74\x6f\x20\x63\x6f"
        "\x6e\x73\x69\x64\x65\x72\x65\x64"
        "\x20\x68\x61\x72\x6d\x66\x75\x6c"
        "\x6c\x00\x90\x90\x1c\x1b\x0a\x20";

Contains three functions and some character data and "encoded" character data.


int f(int x)
{
        static int b = 0; static int s = 0;
        int a = 0, t;
        if (!s) {
                a = b; b = x;
        } else {
                a = x; t = b;
                do {
                        a ^= b;
                        b = (a^b) & b;
                        b <<= 1;
                } while (b);
                b = t;
        }
        s = (s+1) % 2;
        return a;
}

Adds two integers, it temporarily stores the first value and then adds the second and returns the sum on each even numbered call.


int g(int i, int *j)
{
        *j = i;
        i = (int) putchar;
        if (*j == (48 << 1)) 
                __asm volatile (
                                "movl 8(%ebp),%eax;"
                                "leave;"
                                "ret"
                                );
        return (int) puts;
}

g dereferences j and set it to i, returns the address of putchar if i == 96, else it returns the address of puts.


((void(*)()) data)(&a,&b);
((void(*)()) data)(&b,&t);
((void(*)()) data)(&t,&s);

Swaps a and b, b and t, s and t using XOR swap. a = 32, b = 1, t = 8, s = 11


base = ((int(*)())data+addr)();

Takes the return address and returns it, i.e. the address of the next instruction.


addr ^= a;
a ^= addr;
addr ^= a;

Swaps a and addr, a is now -1.


if (a == -1)
    goto over;

is now true.

signal(t,sh);signal(s,sh);signal(u,sh); sets up signal handlers for SIGFPE SIGSEGV and SIGILL.


if (!(s = setjmp(p))) { // true the first time
    q = (void(*)()) g(0x30, &a); // sets a to 48, puts is returned
    q(data + a + i); // calls puts with address of data+a+i = data+48+25
    s = a / (b-1); // divides by zero
    puts("B");
} [...]

Prints goto considered harmfull, raises a SIGFPE.


void sh(int s)
{
        if (s == 010)
                ((void(*)())g(s,&s))("F");
        longjmp(p,s);
}

The signal handler, calls puts with "F". Then longjumps back to the setjump point.


} else {
    puts("D");
    *((int*) base+s) = 0xffffffff;
}

Prints "D" and raises a SIGSEGV by attempting to write to base+s (which in this case is in the middle of main, read-only memory.

Back to the signal handler and then to

} else if (s == 0xb) {
    puts("C");
    ((int(*)(int)) data+addr+(offs/2))(base);
}

Which prints "C" and then calls one of the functions stored in data with base as argument. This function works as longjmp, by replacing the return address with the value of base, which is back to:


        if (a == -1)
                goto over;
        puts("A");
 
        base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
        h(base+addr+offs);
        exit(0);

The value of a is now different from -1, so it prints "A" then calls h after some magic fucking with base and addr and offs. Ultimately exiting.


void h(int i)
{
        int b;
        q = (void(*)()) g(i++[data],&b);
        for (f(b);*(data+i)!=b;++i,f(b))
                q(f(i[data])%0xff);
}

Basically, it prints the "encoded" string, which says "install gentoo"

Name: Anonymous 2012-01-13 22:37

>>347
I got tired mid-way through, so I skipped posting the disassembly output.

Name: Anonymous 2012-01-13 22:40

>>347
>>348

Not OP, but still, very well done figuring it out.

Name: Anonymous 2012-01-13 22:40

>>347
On my machine it doesn't even run.

Name: Anonymous 2012-01-13 22:44

Okay so the guarantee here is that if you use the right version of the right compiler and only use the right compiler flags on the right architecture on the right kernel using the right user environment the program might output those strings.

Name: Anonymous 2012-01-13 22:44

>>350
It relies on your compiler, architecture, OS and current moon phase and planet alignment to work.

Name: Anonymous 2012-01-13 22:45

>>351
Okay so the guarantee here is that if you use the right version of the right compiler and only use the right compiler flags on the right architecture on the right kernel using the right user environment the program might output those strings.
No, if you have all those correct, it will output those strings.

Name: Anonymous 2012-01-13 22:46

>>353 cont'd
But it uses unsafe and unreliable methods for doing so. (Yesyes, and undefined)

Name: Anonymous 2012-01-13 22:47

>>354
and undefined
Then it might output those strings, you can't guarantee otherwise.

Name: Anonymous 2012-01-13 22:49

>>347
SIGILL
Is that supposed to be SIGKILL?

Name: Anonymous 2012-01-13 22:50

>>355
No, it's undefined in the standard (C), but not by the compiler. GCC allows function pointer arithmetics and casting from object data pointers to function pointers. That is the undefined behavior here, because the language specifics doesn't specify it, while the compiler implementation does.

Name: Anonymous 2012-01-13 22:50

>>356
No, SIGILL as in Illegal instruction. You can't catch SIGKILL.

Name: Anonymous 2012-01-13 22:51

>>353
On any conforming platform you may interrupt the program the very instance you start it so it won't output a thing.

Name: Anonymous 2012-01-13 22:52

>>359
Yes, be pedantic then. It might output that. I give up.

Name: Anonymous 2012-01-13 22:52

>>355
see >>360
I'm not going to argue with you any more.

Name: Anonymous 2012-01-13 22:55

>>361
Happy hacking.

Name: Anonymous 2012-01-13 22:56

>>362
You too.

Name: Anonymous 2012-01-13 22:57

>>1
Also, it was quite clever OP, just a tip: Don't come to /prog/ and be so bombastic.

Name: Anonymous 2012-01-14 4:05

Hey, look at that!

Name: Anonymous 2012-01-14 4:05

>>365
*Swipe*

Name: Anonymous 2012-01-14 4:05

>>366
Where did my dubs go? WHY YOU

Name: Anonymous 2012-01-14 4:24

>>367
They terk our dubs!

Don't change these.
Name: Email:
Entire Thread Thread List