]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Modify the sqlite_encode_binary() routine to return the strlen() of the
authordrh <drh@noemail.net>
Mon, 16 Sep 2002 11:44:05 +0000 (11:44 +0000)
committerdrh <drh@noemail.net>
Mon, 16 Sep 2002 11:44:05 +0000 (11:44 +0000)
encoded string.  Also fix a bug that occurs when attempting to encode
a zero-length buffer. (CVS 751)

FossilOrigin-Name: f12c3a25ba5408c2a7c846a9f160416fd188cd26

manifest
manifest.uuid
src/encode.c

index 4938f281182aca034a7fadae3cd52d55742faf97..cb8db1bf09e5acdcf56c4520e48b3c0b976099d3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Do\snot\sput\sa\swrite\slock\son\sthe\smain\sdatabase\sfile\swhen\swriting\sto\sa\stemporary\ntable.\s(CVS\s750)
-D 2002-09-14T13:47:32
+C Modify\sthe\ssqlite_encode_binary()\sroutine\sto\sreturn\sthe\sstrlen()\sof\sthe\nencoded\sstring.\s\sAlso\sfix\sa\sbug\sthat\soccurs\swhen\sattempting\sto\sencode\na\szero-length\sbuffer.\s(CVS\s751)
+D 2002-09-16T11:44:06
 F Makefile.in d6c9a85c2a5e696843201d090dcf8bf2f8716f2a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -22,7 +22,7 @@ F src/btree.c 8024b87635c2adf133f153f1bb595125ec1c7d7b
 F src/btree.h 0ca6c2631338df62e4f7894252d9347ae234eda9
 F src/build.c d41b8da6b52ff84b235a785b226c37f3090ed276
 F src/delete.c aad9d4051ab46e6f6391ea5f7b8994a7c05bdd15
-F src/encode.c 346b12b46148506c32038524b95c4631ab46d760
+F src/encode.c 6c9c87d5b7b2c0101d011ebc283a80abf672a4d1
 F src/expr.c e1327eb020a68ff7c49382e121ad4b71b3441b2a
 F src/func.c e45cd908b9b723d9b91473d09e12c23f786b3fc2
 F src/hash.c 6a6236b89c8c060c65dabd300a1c8ce7c10edb72
@@ -149,7 +149,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 6cb80ae10af60863cc25c22a6442ba1d43b7409c
-R 780c4a4a4908db085bbda24c5386e9ab
+P 3f253afe15d4f7392555f340a41d780d1248087f
+R ae2062ad558397dc7333045d78c8c1e1
 U drh
-Z 662e185948fcdefe24022119237f420c
+Z ff6d471c5e281a3e52ab81c5ecd43f4c
index ef575427d75f50d8f0705cd3decb48cb5c3d4ec3..7c1ddedb2b4c7b727f3523c81f8b0c76f7818c74 100644 (file)
@@ -1 +1 @@
-3f253afe15d4f7392555f340a41d780d1248087f
\ No newline at end of file
+f12c3a25ba5408c2a7c846a9f160416fd188cd26
\ No newline at end of file
index be5a68a7d8060d33b3b78f61cbd29ca2ba018b5a..289600f5dbd61b2cc7527091add30f55cb8089ee 100644 (file)
@@ -15,7 +15,7 @@
 ** data in an SQLite database.  The code in this file is used by any other
 ** part of the SQLite library.
 **
-** $Id: encode.c,v 1.2 2002/04/25 23:06:47 drh Exp $
+** $Id: encode.c,v 1.3 2002/09/16 11:44:06 drh Exp $
 */
 
 /*
 ** In other words, the output will be expanded by as much as 3
 ** bytes for every 253 bytes of input plus 2 bytes of fixed overhead.
 ** (This is approximately 2 + 1.019*n or about a 2% size increase.)
+**
+** The return value is the number of characters in the encoded
+** string, excluding the "\000" terminator.
 */
-void sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
+int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
   int i, j, e, m;
   int cnt[256];
+  if( n<=0 ){
+    out[0] = 'x';
+    out[1] = 0;
+    return 1;
+  }
   memset(cnt, 0, sizeof(cnt));
   for(i=n-1; i>=0; i--){ cnt[in[i]]++; }
   m = n;
@@ -64,7 +72,8 @@ void sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){
       out[j++] = c;
     }
   }
-  out[j++] = 0;
+  out[j] = 0;
+  return j;
 }
 
 /*
@@ -106,7 +115,7 @@ int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
 ** and run the result.
 */
 int main(int argc, char **argv){
-  int i, j, n, m;
+  int i, j, n, m, nOut;
   unsigned char in[30000];
   unsigned char out[33000];
 
@@ -123,7 +132,11 @@ int main(int argc, char **argv){
     }else{
       for(j=0; j<n; j++) in[j] = rand() & 0xff;
     }
-    sqlite_encode_binary(in, n, out);
+    nOut = sqlite_encode_binary(in, n, out);
+    if( nOut!=strlen(out) ){
+      printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
+      exit(1);
+    }
     m = (256*n + 1262)/253;
     printf("size %d->%d (max %d)", n, strlen(out)+1, m);
     if( strlen(out)+1>m ){