by Sergey Lyubka, Cesanta CTO, for Dublin C/C++ User Group
#if defined(__MINGW32__)
typedef struct stat cs_stat_t;
#else
typedef struct _stati64 cs_stat_t;
#endif
int mg_stat(const char *path, cs_stat_t *st) {
....
return _wstati64(wpath, (struct _stati64 *) st);
}
...
mg_printf(conn, "Content-Length: %Iu\r\n", st->st_size);
$ make clean all COPTS="-O0 -g" && ./srv
...
Staring on port 7021
...
Segmentation fault: 11
static int deliver(struct mg_connection *c) {
...
if (!is_first_fragment(p[0])) {
// defragmentation code ...
....
}
...
}
Terminal 1
Terminal 2
$ make clean all COPTS="-O0 -g" && ./srv
...
Staring on port 7021
...
Segmentation fault: 11
static int deliver(struct mg_connection *c) {
...
if (!is_first_fragment(p[0])) {
printf("boyz, tornado is coming\n"); // <--
// defragmentation code ...
....
}
...
}
Terminal 1
Terminal 2
$ make clean all COPTS="-O0 -g" && ./srv
...
Staring on port 7021
...
Segmentation fault: 11
static int deliver(struct mg_connection *c) {
printf("boyz, tornado is coming\n"); // <--
...
if (!is_first_fragment(p[0])) {
....
}
...
}
Terminal 1
Terminal 2
$ make clean all COPTS="-O0 -g" && ./srv
...
Staring on port 7021
...
Segmentation fault: 11
int main(int argc, const char *argv[]) {
printf("boyz, tornado is coming\n"); // <--
...
}
Terminal 1
Terminal 2
static void ev_handler(struct mg_connection *c,
int ev,
void *ev_data) {
...
c->flags |= WEB_TTY;
...
}
Before:
After:
static void ev_handler(struct mg_connection *c,
int ev,
void *ev_data) {
...
c->flags |= WEB_TTY;
...
printf("%p connected\n", c); // <-- Added
...
}
error: format specifies type 'void *' but the argument
has type '<dependent type>' [-Werror,-Wformat]
testutil.c:19:32: error: use of undeclared identifier 'c'
printf("%p connected\n", c);
^
Results in compilation error:
contact me at
sergey.lyubka@cesanta.com