There is a statement in c code I am reviewing
filenum = atoll(item->d_name + strlen(msgid_with_append_str) + 1);
atoll: ascii to long long.
In a certain snapshot,
item->d_name = 050707143827.AAAA.11810.00000001
So item->d_name... is it a char*?
msgid_with_append_str = 050707143827.AAAA.11810
char*?
strlen(msgid_with_append_str) = 23
This is a numeral, as it should be.
resulting in,
filenum = 0
Can anyone explain what is going on? I am not a C programmer by trade.
Thanks.
I suppose it compiles, you say it results in 0. I would say it has to
give an error, but it doesn't:
sensei
ublic$ gcc -Wall -v -std=c99 -pedantic -o a a.c
Using built-in specs.
Target: powerpc-apple-darwin8
Configured with: /private/var/tmp/gcc/gcc-5026.obj~19/src/configure
--disable-checking --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^+.-]*$/s/$/-4.0/
--with-gxx-include-dir=/include/gcc/darwin/4.0/c++
--build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8
--target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.0 (Apple Computer, Inc. build 5026)
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.0/cc1 -quiet -v
-D__DYNAMIC__ a.c -fPIC -quiet -dumpbase a.c -auxbase a -Wall -pedantic
-std=c99 -version -o /var/tmp//ccB0NHW5.s
ignoring nonexistent directory
"/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/../../../../powerpc-apple-darwin8/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/include
/usr/include
/System/Library/Frameworks
/Library/Frameworks
End of search list.
GNU C version 4.0.0 (Apple Computer, Inc. build 5026)
(powerpc-apple-darwin8)
compiled by GNU C version 4.0.0 (Apple Computer, Inc. build 5026).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
as -arch ppc -o /var/tmp//ccRrT9Ac.o /var/tmp//ccB0NHW5.s
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.0/collect2 -dynamic -arch
ppc -weak_reference_mismatches non-weak -o a -lcrt1.o
/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/crt2.o
-L/usr/lib/gcc/powerpc-apple-darwin8/4.0.0
-L/usr/lib/gcc/powerpc-apple-darwin8/4.0.0
-L/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/../../.. /var/tmp//ccRrT9Ac.o
-lgcc -lgcc_eh -lSystemStubs -lmx -lSystem
sensei
ublic$ ./a
result is 0
sensei
ublic$
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
char *d_name = "Hello";
char *msg_id = "world!";
long long i;
i = atoll(d_name + strlen(msg_id) + 1);
printf("result is %lld\n", i);
return 0;
}
Misfunctioning? char* + size_t + 1 (implicit int?) gets converted to a
char* and so the memory location somehow gets to 0?