/ Check-in [fc67adea]
Login

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

Overview
Comment:Add the sqlite3_vsnprintf() interface.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fc67adea414320e0c0b24054f76070cfaeebb401
User & Date: drh 2011-01-05 12:20:09
Context
2011-01-05
13:43
Increment the version number to 3.7.5. check-in: 9ec3896e user: drh tags: trunk
12:50
Add detailed error logging to WAL in an effort to track down an obscure SQLITE_PROTOCOL problem. This code is intended for debugging and not for release. check-in: 2c2afdd0 user: drh tags: wal-trace-375
12:20
Add the sqlite3_vsnprintf() interface. check-in: fc67adea user: drh tags: trunk
2011-01-04
20:06
Fix a null-pointer dereference that can occur on an OOM error while running ANALYZE with SQLITE_ENABLE_STAT2. check-in: 73128d4e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/printf.c.

   930    930   }
   931    931   
   932    932   /*
   933    933   ** sqlite3_snprintf() works like snprintf() except that it ignores the
   934    934   ** current locale settings.  This is important for SQLite because we
   935    935   ** are not able to use a "," as the decimal point in place of "." as
   936    936   ** specified by some locales.
          937  +**
          938  +** Oops:  The first two arguments of sqlite3_snprintf() are backwards
          939  +** from the snprintf() standard.  Unfortunately, it is too late to change
          940  +** this without breaking compatibility, so we just have to live with the
          941  +** mistake.
          942  +**
          943  +** sqlite3_vsnprintf() is the varargs version.
   937    944   */
          945  +char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
          946  +  StrAccum acc;
          947  +  if( n<=0 ) return zBuf;
          948  +  sqlite3StrAccumInit(&acc, zBuf, n, 0);
          949  +  acc.useMalloc = 0;
          950  +  sqlite3VXPrintf(&acc, 0, zFormat, ap);
          951  +  return sqlite3StrAccumFinish(&acc);
          952  +}
   938    953   char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
   939    954     char *z;
   940    955     va_list ap;
   941         -  StrAccum acc;
   942         -
   943         -  if( n<=0 ){
   944         -    return zBuf;
   945         -  }
   946         -  sqlite3StrAccumInit(&acc, zBuf, n, 0);
   947         -  acc.useMalloc = 0;
   948    956     va_start(ap,zFormat);
   949         -  sqlite3VXPrintf(&acc, 0, zFormat, ap);
          957  +  z = sqlite3_vsnprintf(n, zBuf, zFormat, ap);
   950    958     va_end(ap);
   951         -  z = sqlite3StrAccumFinish(&acc);
   952    959     return z;
   953    960   }
   954    961   
   955    962   /*
   956    963   ** This is the routine that actually formats the sqlite3_log() message.
   957    964   ** We house it in a separate routine from sqlite3_log() to avoid using
   958    965   ** stack space on small-stack systems when logging is disabled.

Changes to src/sqlite.h.in.

  1857   1857   **
  1858   1858   ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  1859   1859   ** guarantees that the buffer is always zero-terminated.  ^The first
  1860   1860   ** parameter "n" is the total size of the buffer, including space for
  1861   1861   ** the zero terminator.  So the longest string that can be completely
  1862   1862   ** written will be n-1 characters.
  1863   1863   **
         1864  +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
         1865  +**
  1864   1866   ** These routines all implement some additional formatting
  1865   1867   ** options that are useful for constructing SQL statements.
  1866   1868   ** All of the usual printf() formatting options apply.  In addition, there
  1867   1869   ** is are "%q", "%Q", and "%z" options.
  1868   1870   **
  1869   1871   ** ^(The %q option works like %s in that it substitutes a null-terminated
  1870   1872   ** string from the argument list.  But %q also doubles every '\'' character.
................................................................................
  1920   1922   ** ^(The "%z" formatting option works like "%s" but with the
  1921   1923   ** addition that after the string has been read and copied into
  1922   1924   ** the result, [sqlite3_free()] is called on the input string.)^
  1923   1925   */
  1924   1926   char *sqlite3_mprintf(const char*,...);
  1925   1927   char *sqlite3_vmprintf(const char*, va_list);
  1926   1928   char *sqlite3_snprintf(int,char*,const char*, ...);
         1929  +char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  1927   1930   
  1928   1931   /*
  1929   1932   ** CAPI3REF: Memory Allocation Subsystem
  1930   1933   **
  1931   1934   ** The SQLite core uses these three routines for all of its own
  1932   1935   ** internal memory allocation needs. "Core" in the previous sentence
  1933   1936   ** does not include operating-system specific VFS implementation.  The