lundi 20 juillet 2015

Unexpected behavior with sprintf

I am writing a program and I have a very weird issue.

char *abs_alg *iterator *test_case;
sprintf(abs_alg, "%s/data_root/projects/PROJ-%s/proj/src/%sAbsAlgorithm.cpp", getenv(ALGATOR_ROOT), argv[2], argv[2]);
sprintf(iterator, "%s/data_root/projects/PROJ-%s/proj/src/%sTestSetIterator.cpp", getenv(ALGATOR_ROOT), argv[2], argv[2]);
sprintf(test_case, "%s/data_root/projects/PROJ-%s/proj/src/%sTestCase.cpp", getenv(ALGATOR_ROOT), argv[2], argv[2]);

In last row, I get runtime error: Thread 1: EXC_BAD_ACCESS (code=1, address=0x3)

First two sprintf function are working just fine, but this last one isn't. Also, if I change *char test_case to char test_case[500], then I get error before in program in this line:

char *lib_dir;
sprintf(lib_dir, "%s/data_root/projects/PROJ-%s/lib/", getenv(ALGATOR_ROOT), argv[2]);

I am using XCode-beta 7.0.

g++ --version
Configured with: --prefix=/Applications/http://ift.tt/1JsBhIj --with-gxx-include-dir=/Applications/http://ift.tt/1IepLUd
Apple LLVM version 7.0.0 (clang-700.0.53.3)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

I've been trying to fix this all day but without success. I would appreciate any help I can get.

Aucun commentaire:

Enregistrer un commentaire