Important update:

- LiteProtocolCore:
  - Bug fix: NewCommandStr() cannot shrink CommandStr on CreateCommand
  - Bug fix: AppendParam() cannot pass NULL string value
This commit is contained in:
Charl Wentzel
2017-08-06 12:32:14 +02:00
parent ade3c10a1a
commit c9244555ec
2 changed files with 27 additions and 12 deletions

View File

@@ -196,6 +196,7 @@ bool CLiteProtocol::NewCommandStr()
free( CommandStr ); free( CommandStr );
CommandStr = NULL; CommandStr = NULL;
BufferSize = 0; BufferSize = 0;
Length = 0;
}; };
IncCommandStr( 14 ); IncCommandStr( 14 );
@@ -346,9 +347,18 @@ bool CLiteProtocol::AppendParam( const char * pString, const int pLength )
int StringLen; int StringLen;
// Check if valid // Check if valid
if (!pString) if (!pLength || (!pString && (pLength == -1)))
return false; {
// Increase string length if required
StringLen = 0;
IncCommandStr( Length + 1 );
// Copy string
CommandStr[CurrPos+StringLen] = Separator;
Length += 1; // Allow for separator character
}
else
{
// Increase string length if required // Increase string length if required
StringLen = (pLength < 0)? strlen(pString) : pLength; StringLen = (pLength < 0)? strlen(pString) : pLength;
IncCommandStr( Length + StringLen+1 ); IncCommandStr( Length + StringLen+1 );
@@ -357,10 +367,11 @@ bool CLiteProtocol::AppendParam( const char * pString, const int pLength )
memcpy( &CommandStr[CurrPos], (char*)pString, StringLen ); memcpy( &CommandStr[CurrPos], (char*)pString, StringLen );
CommandStr[CurrPos+StringLen] = Separator; CommandStr[CurrPos+StringLen] = Separator;
Length = Length + StringLen + 1; // Allow for separator character Length = Length + StringLen + 1; // Allow for separator character
}
// Move pointer to end and set end char // Move pointer to end and set end char
CurrParam++; CurrParam++;
CurrPos = CurrPos + StringLen + 1; // Allow for separator character CurrPos += StringLen + 1; // Allow for separator character
CommandStr[CurrPos] = EndChar; CommandStr[CurrPos] = EndChar;
// Update references // Update references

View File

@@ -88,8 +88,12 @@ class CLiteProtocol
int * FromLen = NULL, int * ToLen = NULL, int * CommandLen = NULL ); // Read core parameters from structured command: To, From & Command int * FromLen = NULL, int * ToLen = NULL, int * CommandLen = NULL ); // Read core parameters from structured command: To, From & Command
// Read structured Command string // Read structured Command string
inline int GetNoOfDataParams() { return (NoOfParams - 3); }; // Return number for data (additional) params inline int GetNoOfDataParams() { // Return number for data (additional) params
inline bool GotoDataParam( int ParamNo ) { return (GotoParam( ParamNo+3 )); }; // Goto specific data (additional) param return (NoOfParams - 3);
};
inline bool GotoDataParam( int ParamNo ) { // Goto specific data (additional) param
return (GotoParam( ParamNo+3 ));
};
inline char const * GetDataParamNo( int ParamNo, char ** pString = NULL, int * pLength = NULL ) { // Read specific data param (by number) inline char const * GetDataParamNo( int ParamNo, char ** pString = NULL, int * pLength = NULL ) { // Read specific data param (by number)
return (GetParamNo( ParamNo+3, pString, pLength )); return (GetParamNo( ParamNo+3, pString, pLength ));
}; };