Which compiler are you actually using?
I've tried your code with 3 compilers (gcc, vc6, vc7) and I don't see the effect you're seeing.
I see that -1 seems "special" in microsoft compilers, so that may be confusing you.
With different return results, I see very different paths. The "jump" to what looks like an exception eventually leads to the return 0, which I figure is the "there is no exception" code being executed.
Code:
#include <iostream>
using namespace std;
inline int my_strcpy(char* source, char* target){
int counter(0);
while (*target!=0){
*source++=*target++;
++counter;
}
*source = 0;
return counter+1;
}
struct x {
char ServerName[10];
char MapName[10];
char Game[10];
char GameType[10];
unsigned short PlayerCount;
unsigned short MaxPlayers;
};
int foo ( char *bufptr, x *target ) {
try{
bufptr += my_strcpy(target->ServerName, bufptr);
bufptr += my_strcpy(target->MapName, bufptr);
bufptr += my_strcpy(target->Game, bufptr);
bufptr += my_strcpy(target->GameType, bufptr);
bufptr += 2; //Skip appid because it is no use to us
target->PlayerCount = static_cast<unsigned short>(*bufptr++);
target->MaxPlayers = static_cast<unsigned short>(*bufptr++);
bufptr+=3;
}
catch (std::bad_alloc&){
return -2;
}
catch(void *){
return -3;
}
return 0;
}
int main ( ) {
return 0;
}
// VC6 ASM
// cl /Fafoo.s /GX foo.cpp
; Line 32
mov eax, DWORD PTR _bufptr$[ebp]
add eax, 3
mov DWORD PTR _bufptr$[ebp], eax
; Line 34
jmp SHORT $L7372
$L8456:
; Line 35
mov DWORD PTR $T8453[ebp], -2 ; fffffffeH
mov eax, $L8458
ret 0
$L8458:
mov eax, DWORD PTR $T8453[ebp]
jmp SHORT $L7371
$L8457:
; Line 38
mov DWORD PTR $T8454[ebp], -3 ; fffffffdH
mov eax, $L8459
ret 0
$L8459:
mov eax, DWORD PTR $T8454[ebp]
jmp SHORT $L7371
$L7372:
; Line 40
mov DWORD PTR __$EHRec$[ebp+12], -1
xor eax, eax
$L7371:
; Line 41
mov ecx, DWORD PTR __$EHRec$[ebp+4]
mov DWORD PTR fs:__except_list, ecx
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
// VC7 ASM
; Line 32
mov eax, DWORD PTR _bufptr$[ebp]
add eax, 3
mov DWORD PTR _bufptr$[ebp], eax
jmp SHORT $L9570
$L9571:
; Line 35
mov DWORD PTR $T9568[ebp], -2 ; fffffffeH
mov eax, $L9574
ret 0
$L9572:
; Line 38
mov DWORD PTR $T9569[ebp], -3 ; fffffffdH
mov eax, $L9576
ret 0
$L9570:
; Line 39
mov DWORD PTR __$EHRec$[ebp+12], -1
; Line 40
jmp SHORT $L9575
$L9576:
; Line 38
mov eax, DWORD PTR $T9569[ebp]
jmp SHORT $L8439
$L9575:
; Line 40
jmp SHORT $L9573
$L9574:
; Line 35
mov eax, DWORD PTR $T9568[ebp]
jmp SHORT $L8439
$L9573:
; Line 40
xor eax, eax
$L8439:
; Line 41
mov ecx, DWORD PTR __$EHRec$[ebp+4]
mov DWORD PTR fs:__except_list, ecx
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
PS
Your English seems pretty reasonable to me