Check-in [0cbc5d295c]
Not logged in

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

Overview
SHA1 Hash:0cbc5d295c9911b00ed405d301a7b8e76db77b41
Date: 2010-03-10 17:18:42
User: drh
Comment:Make sure the return value of db_text() is always something obtained from malloc() or else NULL. Strdup() the default value if the default value is used.
Tags And Properties
Changes

Changes to src/db.c

   500 ** of the result set as a string.  Space to hold the string is                        500 ** of the result set as a string.  Space to hold the string is
   501 ** obtained from malloc().  If the result set is empty, return                        501 ** obtained from malloc().  If the result set is empty, return
   502 ** zDefault instead.                                                                  502 ** zDefault instead.
   503 */                                                                                    503 */
   504 char *db_text(char *zDefault, const char *zSql, ...){                                 504 char *db_text(char *zDefault, const char *zSql, ...){
   505   va_list ap;                                                                         505   va_list ap;
   506   Stmt s;                                                                             506   Stmt s;
   507   char *z = zDefault;                                                            |    507   char *z;
   508   va_start(ap, zSql);                                                                 508   va_start(ap, zSql);
   509   db_vprepare(&s, zSql, ap);                                                          509   db_vprepare(&s, zSql, ap);
   510   va_end(ap);                                                                         510   va_end(ap);
   511   if( db_step(&s)==SQLITE_ROW ){                                                      511   if( db_step(&s)==SQLITE_ROW ){
   512     z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));                               512     z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
                                                                                        >    513   }else if( zDefault ){
                                                                                        >    514     z = mprintf("%s", zDefault);
                                                                                        >    515   }else{
                                                                                        >    516     z = 0;
   513   }                                                                                   517   }
   514   db_finalize(&s);                                                                    518   db_finalize(&s);
   515   return z;                                                                           519   return z;
   516 }                                                                                     520 }
   517                                                                                       521 
   518 /*                                                                                    522 /*
   519 ** Initialize a new database file with the given schema.  If anything                 523 ** Initialize a new database file with the given schema.  If anything