/ Check-in [4622b7ce]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sure malloc(0) always returns NULL. Fix for ticket #171. (CVS 764)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4622b7ce8f4727a6405ddf4f0af701db86da86bf
User & Date: drh 2002-10-20 15:46:23
Context
2002-10-20
15:53
Work around a bug in the Borland C compiler. Ticket #172. (CVS 765) check-in: 3ef29256 user: drh tags: trunk
15:46
Make sure malloc(0) always returns NULL. Fix for ticket #171. (CVS 764) check-in: 4622b7ce user: drh tags: trunk
2002-10-19
20:16
Speed improvement by avoiding a call to sqliteBtreeLast() when inserting a new row into a table. (CVS 763) check-in: d0af59fe user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.51 2002/09/30 01:31:22 drh Exp $
           17  +** $Id: util.c,v 1.52 2002/10/20 15:46:23 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <stdarg.h>
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** If malloc() ever fails, this global variable gets set to 1.
................................................................................
   213    213   #if !defined(MEMORY_DEBUG)
   214    214   
   215    215   /*
   216    216   ** Allocate new memory and set it to zero.  Return NULL if
   217    217   ** no memory is available.
   218    218   */
   219    219   void *sqliteMalloc(int n){
   220         -  void *p = malloc(n);
          220  +  void *p;
          221  +  if( n==0 ) return 0;
          222  +  p = malloc(n);
   221    223     if( p==0 ){
   222    224       sqlite_malloc_failed++;
   223    225       return 0;
   224    226     }
   225    227     memset(p, 0, n);
   226    228     return p;
   227    229   }