1

By building dmalloc lib with following setting in conf.h file

#define HAVE_VPRINTF 0
#define HAVE_SNPRINTF 0
#define HAVE_VSNPRINTF 0

and run my code after linking , log file content have unformatting address info to function names and line numbers.

Unformatted log o/p is given below.

        Venkatesh:~/Dmalloc/dmalloc-5.5.2$ cat logfile
        %ld: %lu: Dmalloc version '%s' from '%s'
        %ld: %lu: flags = %#x, logfile '%s'
        %ld: %lu: interval = %lu, addr = %#lx, seen # = %ld, limit = %ld
        %ld: %lu: starting time = %s
        %ld: %lu: process pid = %ld
        %ld: %lu:   error details: %s
        %ld: %lu:   pointer '%#lx' from '%s' prev access '%s'
        %ld: %lu:   dump of proper fence-top bytes: '%.*s'
        %ld: %lu:   dump of '%#lx'%+d: '%.*s'
        %ld: %lu:   next pointer '%#lx' (size %u) may have run under from '%s'
        %ld: %lu: ERROR: %s: %s (err %d)


If I define HAVE_VSNPRINTF to 1, then I log file has only dmalloc log header, no information about errors as given below.

        Venkatesh:~/Dmalloc/dmalloc-5.5.2$ cat logfile
        1450864250: 5: Dmalloc version '5.5.2' from 'http://dmalloc.com/'
        1450864250: 11: flags = 0x4f4e503, logfile 'logfile'
        1450864250: 17: interval = 100, addr = 0, seen # = 0, limit = 0
        1450864250: 25: starting time = 1450864250
        1450864250: 31: process pid = 10270

My test code is as below.

    #include <stdio.h>
    #include <stdlib.h>

    #ifdef DMALLOC
    #include "dmalloc.h"
    #endif

    int main ()
    {
            char *p;
            p = malloc (50);
            p[51] = 'c'; //Writing character beyond allocated range
            return 0;
    }

Dmalloc optins I am using is : DMALLOC_OPTIONS=debug=0x4f4ed03,inter=100,log=logfile

venkatesh
  • 11
  • 1
  • The code contains undefined behaviour. even accessing `p[50]` is beyond the available offset because in C, array offsets start at 0 and continue to size of array -1. Undefined behaviour can lead to a seg fault event! – user3629249 Dec 25 '15 at 09:25
  • you might want to read and its' related pages – user3629249 Dec 25 '15 at 10:06
  • ya, intentionally , I am writing data into p[50] so that dmalloc gives me warning regarding the same. But my question is, even though it is giving the warning for me, when i by define HAVE_VPRINTF , HAVE_SNPRINTF and HAVE_VSNPRINTF as 0, it is printing error messages but they are all unformatted. But if I make HAVE_VPRINTF , HAVE_SNPRINTF and HAVE_VSNPRINTF as 1 , then dmalloc just prints its header info with formatted strings but not displays error details. – venkatesh Dec 28 '15 at 09:27

0 Answers0