From: "n.pettik" <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: Roman Khabibov <roman.habibov@tarantool.org> Subject: [tarantool-patches] Re: [PATCH] sql: fix bug with BLOB TRIM() when X'00' in char set Date: Tue, 18 Dec 2018 11:40:05 +0300 [thread overview] Message-ID: <D9B9528A-5E3E-4AF1-B2CE-90BA417B969A@tarantool.org> (raw) In-Reply-To: <20181215105741.28464-1-roman.habibov@tarantool.org> > On 15 Dec 2018, at 13:57, Roman Khabibov <roman.habibov@tarantool.org> wrote: > > The reason for the bug was that X'00' is a terminal symbol. If the char set > contained X'00', all other characters after its (inculding itself) are then > ignored. Nit: ‘… after its’ -> ‘… after it’. Nit: inculding -> including. Nit: ‘are then ignored’ -> ‘are ignored’. Nit: I wouldn’t mix first and second conditions: ‘If the char set contains …, all characters are ignored...' > > Closes #3543 > > Branch: https://github.com/tarantool/tarantool/tree/romankhabibov/gh-3543-trim-terminal > Issue: https://github.com/tarantool/tarantool/issues/3543 You should put links to the branch and issue below delimiter ---, not above. > --- > src/box/sql/func.c | 18 +++++- > test/sql-tap/func.test.lua | 126 ++++++++++++++++++++++++++++++++++++- > 2 files changed, 140 insertions(+), 4 deletions(-) > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index 9667aead5..5beba7bd2 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -1224,8 +1224,16 @@ trimFunc(sqlite3_context * context, int argc, sqlite3_value ** argv) > return; > } else { > const unsigned char *z; > - for (z = zCharSet, nChar = 0; *z; nChar++) { Lets start from putting here comments which explain what is going on here (how you algorithm/approach works). Then, lets choose more suitable names for variables: length, sizeInChar and nChar sound very similar (if you can’t come up with better names, then at least mention in comment what they mean). > + int sizeInChar = sqlite3_value_bytes(argv[1]); > + int length = 0; What is the difference between sizeInChar, length and nChar? > + z = zCharSet; > + nChar = 0; > + const unsigned char *zStepBack; > + while(sizeInChar - length) { We use explicit conditions as a predicate value. In other words: while (sizeInChar - length > 0) Also, it would be better if you declare and initialise var at once: const unsigned char *z = zCharSet; > + zStepBack = z; > SQLITE_SKIP_UTF8(z); > + length += z - zStepBack; > + nChar++; > } > if (nChar > 0) { > azChar = > @@ -1235,10 +1243,16 @@ trimFunc(sqlite3_context * context, int argc, sqlite3_value ** argv) > return; > } > aLen = (unsigned char *)&azChar[nChar]; > - for (z = zCharSet, nChar = 0; *z; nChar++) { > + z = zCharSet; > + nChar = 0; > + length = 0; > + while(sizeInChar - length) { > azChar[nChar] = (unsigned char *)z; > + zStepBack = z; > SQLITE_SKIP_UTF8(z); > + length += z - zStepBack; > aLen[nChar] = (u8) (z - azChar[nChar]); > + nChar++; > } > } > } > diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua > index 393212968..b7b8e7c4c 100755 > --- a/test/sql-tap/func.test.lua > +++ b/test/sql-tap/func.test.lua > @@ -1,6 +1,6 @@ > #!/usr/bin/env tarantool > test = require("sqltester") > -test:plan(14535) > +test:plan(14547) > > --!./tcltestrunner.lua > -- 2001 September 15 > @@ -2100,11 +2100,133 @@ test:do_execsql_test( > -- </func-22.22> > }) > > -- This is to test the deprecated sqlite3_aggregate_count() API. > -- > --test:do_test( > -- "func-23.1", > --- function() > +-- function()S Garbage diff.
next prev parent reply other threads:[~2018-12-18 8:40 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-15 10:57 [tarantool-patches] " Roman Khabibov 2018-12-18 8:40 ` n.pettik [this message] 2018-12-18 14:30 ` [tarantool-patches] " Roman 2018-12-25 11:40 ` n.pettik 2018-12-26 13:56 ` Roman 2018-12-28 11:09 ` n.pettik 2018-12-20 20:41 ` Vladislav Shpilevoy 2018-12-27 12:28 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=D9B9528A-5E3E-4AF1-B2CE-90BA417B969A@tarantool.org \ --to=korablev@tarantool.org \ --cc=roman.habibov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH] sql: fix bug with BLOB TRIM() when X'\''00'\'' in char set' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox