diff --git a/compiler2/PredefFunc.cc b/compiler2/PredefFunc.cc index 3e23e39f8d8299de4728cee01f0a8083b6f8b028..4f80aedfce16d71cccdcbd5e48c072632cb5545a 100644 --- a/compiler2/PredefFunc.cc +++ b/compiler2/PredefFunc.cc @@ -620,6 +620,16 @@ namespace Common { string* regexp(const string& instr, const string& expression, const Int& groupno, bool nocase) + { + string* retval = regexp_internal(instr, expression, groupno, nocase); + if (retval != NULL) { + return retval; + } + return new string(); + } + + string* regexp_internal(const string& instr, const string& expression, + const Int& groupno, bool nocase) { string *retval=0; @@ -664,13 +674,11 @@ namespace Common { if(pmatch[nmatch].rm_so != -1 && pmatch[nmatch].rm_eo != -1) retval = new string(instr.substr(pmatch[nmatch].rm_so, pmatch[nmatch].rm_eo - pmatch[nmatch].rm_so)); - else retval=new string(); } Free(pmatch); if(ret_val!=0) { if(ret_val==REG_NOMATCH) { regfree(&posix_regexp); - retval=new string(); } else { /* regexp error */ diff --git a/compiler2/PredefFunc.hh b/compiler2/PredefFunc.hh index 026ded84c876445723f49e16912f5ee910d6ac6a..0be5e57b5dd0f12a3323a191ffba1985139302a6 100644 --- a/compiler2/PredefFunc.hh +++ b/compiler2/PredefFunc.hh @@ -61,8 +61,13 @@ namespace Common { extern Real int2float(const int_val_t& value); extern int_val_t* float2int(const Real& value, const Location& loc); extern string* float2str(const Real& value); + // returns a pointer to an empty string if the input doesn't match the expression (as in TTCN-3) extern string* regexp(const string& instr, const string& expression, const Int& groupno, bool nocase); + // returns a null pointer if the input doesn't match the expression + // (to distinguish between a matching empty string and non-matching) + extern string* regexp_internal(const string& instr, const string& expression, + const Int& groupno, bool nocase); extern ustring* regexp(const ustring& instr, const ustring& expression, const Int& groupno, bool nocase); extern string* remove_bom(const string& encoded_value); diff --git a/compiler2/subtypestuff.cc b/compiler2/subtypestuff.cc index 4e1211aa3520e4dfae5b72bea34248e766afde64..5e77bffb0588fd9565e272a23bd660c408321e43 100644 --- a/compiler2/subtypestuff.cc +++ b/compiler2/subtypestuff.cc @@ -508,8 +508,8 @@ tribool StringPatternConstraint::match(const string& str) const { string patt = pattern->get_full_str(); if (patt.size()==0) return TRIBOOL(str.size()==0); - string *result = regexp(str, string('(')+patt+string(')'), 0, pattern->get_nocase()); - bool rv = (result->size()!=0); + string *result = regexp_internal(str, string('(')+patt+string(')'), 0, pattern->get_nocase()); + bool rv = (result!=0); delete result; return TRIBOOL(rv); } diff --git a/regression_test/compileonly/Bug568340/.gitignore b/regression_test/compileonly/Bug568340/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..67fd87c0c5eb53571057a6381dc2b41ba1f14049 --- /dev/null +++ b/regression_test/compileonly/Bug568340/.gitignore @@ -0,0 +1,4 @@ +Bug568340 +Bug568340.exe +Bug568340*.cc +Bug568340*.hh diff --git a/regression_test/compileonly/Bug568340/Bug568340.ttcn b/regression_test/compileonly/Bug568340/Bug568340.ttcn new file mode 100644 index 0000000000000000000000000000000000000000..d46b687fc6474e9a60892e75ef1eb7e1dddc0594 --- /dev/null +++ b/regression_test/compileonly/Bug568340/Bug568340.ttcn @@ -0,0 +1,20 @@ +/****************************************************************************** + * Copyright (c) 2000-2020 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html + * + * Contributors: + * Baranyi, Botond + * + ******************************************************************************/ + +// pattern subtyping for empty strings (bug 568340) +module Bug568340 { + +type charstring T (pattern "(/?+)#(0,1)"); + +const T val := ""; + +} diff --git a/regression_test/compileonly/Bug568340/Makefile b/regression_test/compileonly/Bug568340/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9552e04323eb50bc056450d7e77369f1bb29e0a1 --- /dev/null +++ b/regression_test/compileonly/Bug568340/Makefile @@ -0,0 +1,50 @@ +############################################################################## +# Copyright (c) 2000-2020 Ericsson Telecom AB +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html +# +# Contributors: +# Botond, Baranyi +# +############################################################################## +TOPDIR := ../.. +include $(TOPDIR)/Makefile.regression + +.PHONY: all clean dep + +TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX) + +TTCN3_MODULES = Bug568340.ttcn + +GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc) +GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh) +ifdef CODE_SPLIT +GENERATED_SOURCES := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), .cc _seq.cc _set.cc _seqof.cc _setof.cc _union.cc)) +else ifdef SPLIT_TO_SLICES +POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_)) +POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc)) +GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES))) +GENERATED_SOURCES += $(GENERATED_SOURCES2) +endif + +OBJECTS = $(GENERATED_SOURCES:.cc=.o) + +TARGET = Bug568340$(EXESUFFIX) + +all: $(TARGET) + +$(TARGET): $(GENERATED_SOURCES) $(USER_SOURCES) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ -L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \ + -L$(OPENSSL_DIR)/lib -lcrypto $($(PLATFORM)_LIBS) + +$(GENERATED_SOURCES) $(GENERATED_HEADERS): $(TTCN3_MODULES) + $(TTCN3_COMPILER) $(COMPILER_FLAGS) $^ + +clean distclean: + $(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \ + $(GENERATED_SOURCES) compile *.log + +dep: $(GENERATED_SOURCES) + makedepend $(CPPFLAGS) $(GENERATED_SOURCES) diff --git a/regression_test/compileonly/Makefile b/regression_test/compileonly/Makefile index b37605bee26015dedd18ef2ba5e9e6e180136966..cf0922753b142d0de103d0ff92b9498918bb3cb9 100644 --- a/regression_test/compileonly/Makefile +++ b/regression_test/compileonly/Makefile @@ -31,7 +31,7 @@ CODIRS := dynamicTemplate styleGuide topLevelPdu \ asn1_hyphen nameClash portTranslation UntaggedOnTopLevelUnionSwitch \ typeDescrGenWIthNoXER languageSpec asn1_opentype openTypeXER \ asnStringSubtypes componentParameter realtimeKeywords Bug550526 \ - Bug550623 Bug552232 + Bug550623 Bug552232 Bug568340 ifdef DYN CODIRS += mfgen-xsd