need help understanding the movzbl call in this function

A corresponding C function would be something like Specifically, the movzbl instruction fetches the byte stored at the sum of the two parameters, zero pads it, and stores it into eax. The movsbl instruction takes the lowest byte of eax, sign extends it, and stores the result back in eax.

How to correctly use the extern keyword in C

extern changes the linkage. With the keyword, the function / variable is assumed to be available somewhere else and the resolving is deferred to the linker. There’s a difference between extern on functions and on variables. For variables it doesn’t instantiate the variable itself, i.e. doesn’t allocate any memory. This needs to be done somewhere else. Thus it’s important if … Read more

Categories C Tags

Using %s in C correctly – very basic level

For both *printf and *scanf, %s expects the corresponding argument to be of type char *, and for scanf, it had better point to a writable buffer (i.e., not a string literal). Using %s in scanf without an explcit field width opens the same buffer overflow exploit that gets did; namely, if there are more characters in the input stream than the target buffer is sized to hold, scanf will … Read more

Categories C Tags

Connect: Socket operation on non-socket

I see the problem. It’s this line: The == operator has precedence over the = operator. Look at the way you have the parentheses structured on that expression a bit more carefully to see what I mean. sockfd is getting initialize to “0” as a result of being assigned a boolean expression (socket(…) == -1). … Read more

How do I properly compare strings in C?

You can’t (usefully) compare strings using != or ==, you need to use strcmp: The reason for this is because != and == will only compare the base addresses of those strings. Not the contents of the strings themselves.

Connect: Socket operation on non-socket

I see the problem. It’s this line: The == operator has precedence over the = operator. Look at the way you have the parentheses structured on that expression a bit more carefully to see what I mean. sockfd is getting initialize to “0” as a result of being assigned a boolean expression (socket(…) == -1). … Read more