Skip to content

Commit

Permalink
Fix incorrect assert exposed by v63005/gtm8956 subtest
Browse files Browse the repository at this point in the history
When ydb_chset env var is set to "M", compiling the following line

	set c=$PIECE("Hello "_$ZCH(190)_" world!",$ZCH(191),1,2)

Failed an assert

%YDB-F-ASSERT, Assert failed in sr_unix/gtm_utf8.c line 273 for expression (gtm_utf8_mode)

with the following C-stack

 #6  utf8_badchar_real () at sr_unix/gtm_utf8.c:273
 #7  utf8_badchar_dec () at sr_unix/gtm_utf8.c:249
 #8  valid_utf_string () at sr_unix/gtm_utf8.c:410
 #9  op_fnzpiece () at sr_port/op_fnzpiece.c:53
 #10 f_piece () at sr_unix/f_piece.c:171
 #11 expritem () at sr_port/expritem.c:619
 #12 expratom () at sr_port/expratom.c:29
 #13 eval_expr () at sr_port/eval_expr.c:63
 #14 expr () at sr_port/expr.c:29
 #15 m_write () at sr_port/m_write.c:71
 #16 cmd () at sr_port/cmd.c:302
 #17 linetail () at sr_port/linetail.c:35
 #18 line () at sr_port/line.c:230
 #19 compiler_startup () at sr_port/compiler_startup.c:144
 #20 compile_source_file () at sr_unix/source_file.c:132
 #21 gtm_compile () at sr_unix/gtm_compile.c:120

The assert that failed is correct. The issue is that we called the utf8_badchar_real() function
in non-UTF8 mode (i.e. when "gtm_utf8_mode" is 0). The issue is in op_fnzpiece() where we
invoke the valid_utf_string() function only if we are in UTF-8 mode (indicated by "gtm_utf8_mode == 1").
The assert (likely introduced as part of GTM-7762 in GT.M V6.3-000) is now fixed to take care of this.
  • Loading branch information
nars1 committed Oct 17, 2018
1 parent 545fda9 commit aeb1036
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions sr_port/op_fnzpiece.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2006-2015 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
Expand All @@ -17,6 +20,10 @@

#include "gtm_utf8.h"

#ifdef DEBUG
GBLREF boolean_t gtm_utf8_mode;
#endif

/* --------------------------------------------------------------------
* NOTE: This module is a near copy of sr_unix/op_fnpiece.c differing
* only in that it calls "matchb" instead of "matchc" to do matching.
Expand Down Expand Up @@ -46,12 +53,10 @@ void op_fnzpiece(mval *src, mval *del, int first, int last, mval *dst)
char *match_start;
int match_res;
delimfmt unichar;

DCL_THREADGBL_ACCESS;
SETUP_THREADGBL_ACCESS;

assert(!TREF(compile_time) || valid_utf_string(&src->str));

SETUP_THREADGBL_ACCESS;
assert(!TREF(compile_time) || !gtm_utf8_mode || valid_utf_string(&src->str));
if (--first < 0)
first = 0;
if ((piece_cnt = last - first) < 1)
Expand Down

0 comments on commit aeb1036

Please sign in to comment.