What is a glibc free/malloc/realloc invalid next size/invalid pointer error and how to fix it?

Answer for Example Question unwind gave the accepted answer to the example question: Your code is wrong. You are allocating space for a single pointer (malloc(sizeof(char*))), but no characters. You are overwriting your allocated space with all the strings, causing undefined behavior (in this particular case, corrupting malloc()‘s book-keeping data). You don’t need to allocate … Read more

difference between %ms and %s scanf

The C Standard does not define such an optional character in the scanf() formats. The GNU lib C, does define an optional a indicator this way (from the man page for scanf): An optional a character. This is used with string conversions, and relieves the caller of the need to allocate a corresponding buffer to … Read more

How to upgrade glibc from version 2.12 to 2.14 on CentOS?

You cannot update glibc on Centos 6 safely. However you can install 2.14 alongside 2.12 easily, then use it to compile projects etc. Here is how: mkdir ~/glibc_install; cd ~/glibc_install wget http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz tar zxvf glibc-2.14.tar.gz cd glibc-2.14 mkdir build cd build ../configure –prefix=/opt/glibc-2.14 make -j4 sudo make install export LD_LIBRARY_PATH=/opt/glibc-2.14/lib

Compiling without libc

If you compile your code with -nostdlib, you won’t be able to call any C library functions (of course), but you also don’t get the regular C bootstrap code. In particular, the real entry point of a program on Linux is not main(), but rather a function called _start(). The standard libraries normally provide a … Read more

Why is this code using strlen heavily 6.5x slower with GCC optimizations enabled?

Testing your code on Godbolt’s Compiler Explorer provides this explanation: at -O0 or without optimisations, the generated code calls the C library function strlen; at -O1 the generated code uses a simple inline expansion using a rep scasb instruction; at -O2 and above, the generated code uses a more elaborate inline expansion. Benchmarking your code … Read more