Commit bae05f5b authored by Gábor Szalai's avatar Gábor Szalai
Browse files

Prevent "Data remained" warning in TEXT decoder (bug 551516)

Correctly prevent the
"Data remained at the end of the stream after successful decoding: '00'O"
warning in TEXT decoder, by removing the added NULL from the end of the buffer

Change-Id: Ibc697cf615a55b21dfcd92371b404c54615109d7
parent 2b96e78d
......@@ -226,7 +226,9 @@ void def_encdec(const char *p_classname,
" TTCN_EncDec_ErrorContext::error_internal\n"
" (\"No TEXT descriptor available for type '%%s'.\", p_td.name);\n"
" const unsigned char *b_data=p_buf.get_data();\n"
" int null_added=0;\n"
" if(b_data[p_buf.get_len()-1]!='\\0'){\n"
" null_added=1;\n"
" p_buf.set_pos(p_buf.get_len());\n"
" p_buf.put_zero(8,ORDER_LSB);\n"
" p_buf.rewind();\n"
......@@ -235,6 +237,12 @@ void def_encdec(const char *p_classname,
" ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"
"\"Can not decode type '%%s', because invalid or incomplete"
" message was received\", p_td.name);\n"
" if(null_added){\n"
" size_t actpos=p_buf.get_pos();\n"
" p_buf.set_pos(p_buf.get_len()-1);\n"
" p_buf.cut_end();\n"
" p_buf.set_pos(actpos);\n"
" }\n"
" break;}\n"
/* XERSTUFF decoder */
" case TTCN_EncDec::CT_XER: {\n"
......
......@@ -153,7 +153,9 @@ void Base_Type::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -163,6 +165,12 @@ void Base_Type::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
"Can not decode type '%s', because invalid or incomplete"
" message was received"
, p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER: {
TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
......
......@@ -304,7 +304,9 @@ void BOOLEAN::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -314,6 +316,12 @@ void BOOLEAN::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
"Can not decode type '%s', because invalid or incomplete"
" message was received"
, p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER: {
TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
......
......@@ -874,7 +874,9 @@ void CHARSTRING::decode(const TTCN_Typedescriptor_t& p_td,
TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -884,6 +886,12 @@ void CHARSTRING::decode(const TTCN_Typedescriptor_t& p_td,
"Can not decode type '%s', because invalid or incomplete"
" message was received"
, p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER: {
TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
......
......@@ -854,7 +854,9 @@ void INTEGER::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -864,6 +866,12 @@ void INTEGER::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
"Can not decode type '%s', because invalid or incomplete"
" message was received"
, p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER: {
TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
......
......@@ -699,7 +699,9 @@ void OCTETSTRING::decode(const TTCN_Typedescriptor_t& p_td,
TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -709,6 +711,12 @@ void OCTETSTRING::decode(const TTCN_Typedescriptor_t& p_td,
"Can not decode type '%s', because invalid or incomplete"
" message was received"
, p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER: {
TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
......
......@@ -1205,7 +1205,9 @@ void UNIVERSAL_CHARSTRING::decode(const TTCN_Typedescriptor_t& p_td,
TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -1215,6 +1217,12 @@ void UNIVERSAL_CHARSTRING::decode(const TTCN_Typedescriptor_t& p_td,
"Can not decode type '%s', because invalid or incomplete"
" message was received"
, p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER : {
unsigned XER_coding=va_arg(pvar, unsigned);
......
......@@ -1910,7 +1910,9 @@ void Record_Of_Type::decode(const TTCN_Typedescriptor_t& p_td,
if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal
("No TEXT descriptor available for type '%s'.", p_td.name);
const unsigned char *b=p_buf.get_data();
int null_added=0;
if(b[p_buf.get_len()-1]!='\0'){
null_added=1;
p_buf.set_pos(p_buf.get_len());
p_buf.put_zero(8,ORDER_LSB);
p_buf.rewind();
......@@ -1918,6 +1920,12 @@ void Record_Of_Type::decode(const TTCN_Typedescriptor_t& p_td,
if(TEXT_decode(p_td,p_buf,limit)<0)
ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', "
"because invalid or incomplete message was received", p_td.name);
if(null_added){
size_t actpos=p_buf.get_pos();
p_buf.set_pos(p_buf.get_len()-1);
p_buf.cut_end();
p_buf.set_pos(actpos);
}
break;}
case TTCN_EncDec::CT_XER: {
TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment