Stack smashing detected

Stack Smashing here is actually caused due to a protection mechanism used by gcc to detect buffer overflow errors. For example in the following snippet: #include <stdio.h> void func() { char array[10]; gets(array); } int main(int argc, char **argv) { func(); } The compiler, (in this case gcc) adds protection variables (called canaries) which have … Read more

How do I use valgrind to find memory leaks?

How to Run Valgrind Not to insult the OP, but for those who come to this question and are still new to Linux—you might have to install Valgrind on your system. sudo apt install valgrind # Ubuntu, Debian, etc. sudo yum install valgrind # RHEL, CentOS, Fedora, etc. sudo pacman -Syu valgrind # Arch, Manjaro, … Read more

C default arguments

Wow, everybody is such a pessimist around here. The answer is yes. It ain’t trivial: by the end, we’ll have the core function, a supporting struct, a wrapper function, and a macro around the wrapper function. In my work I have a set of macros to automate all this; once you understand the flow it’ll … Read more

Passing variable number of arguments around

To pass the ellipses on, you initialize a va_list as usual and simply pass it to your second function. You don’t use va_arg(). Specifically; void format_string(char *fmt,va_list argptr, char *formatted_string); void debug_print(int dbg_lvl, char *fmt, …) { char formatted_string[MAX_FMT_SIZE]; va_list argptr; va_start(argptr,fmt); format_string(fmt, argptr, formatted_string); va_end(argptr); fprintf(stdout, “%s”,formatted_string); }

How to print a int64_t type in C

For int64_t type: #include <inttypes.h> int64_t t; printf(“%” PRId64 “\n”, t); for uint64_t type: #include <inttypes.h> uint64_t t; printf(“%” PRIu64 “\n”, t); you can also use PRIx64 to print in hexadecimal. cppreference.com has a full listing of available macros for all types including intptr_t (PRIxPTR). There are separate macros for scanf, like SCNd64. A typical … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)