1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

fix for 0 length modifier value

This commit is contained in:
tg(x) 2011-05-04 18:58:46 +02:00
parent 220481d954
commit fea30e3688

View file

@ -73,7 +73,7 @@ char isKwChar (uint8_t c)
* @return PSYC_PARSE_ERROR or PSYC_PARSE_SUCCESS * @return PSYC_PARSE_ERROR or PSYC_PARSE_SUCCESS
*/ */
static inline static inline
psycParseRC psyc_parseKeyword (psycParseState* state, psycString* name) psycParseRC psyc_parseKeyword (psycParseState *state, psycString *name)
{ {
name->ptr = state->buffer.ptr + state->cursor; name->ptr = state->buffer.ptr + state->cursor;
name->length = 0; name->length = 0;
@ -104,8 +104,8 @@ psycParseRC psyc_parseBinaryValue (psycParseState *state, psycString *value,
size_t remaining = *length - *parsed; size_t remaining = *length - *parsed;
value->ptr = state->buffer.ptr + state->cursor; value->ptr = state->buffer.ptr + state->cursor;
if (state->cursor + remaining > state->buffer.length) // is the length larger than this buffer? if (state->cursor + remaining > state->buffer.length)
{ { // value doesn't fit in the buffer completely
value->length = state->buffer.length - state->cursor; value->length = state->buffer.length - state->cursor;
state->cursor += value->length; state->cursor += value->length;
*parsed += value->length; *parsed += value->length;
@ -168,7 +168,7 @@ psycParseRC psyc_parseModifier (psycParseState *state, char *oper,
return PSYC_PARSE_ERROR_MOD_TAB; return PSYC_PARSE_ERROR_MOD_TAB;
if (++(state->cursor) >= state->buffer.length) if (++(state->cursor) >= state->buffer.length)
return PSYC_PARSE_INCOMPLETE; return length ? PSYC_PARSE_INCOMPLETE : PSYC_PARSE_SUCCESS; // if length=0 we're done
ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed)); ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed));
if (ret == PSYC_PARSE_INCOMPLETE) if (ret == PSYC_PARSE_INCOMPLETE)
@ -197,8 +197,8 @@ psycParseRC psyc_parseModifier (psycParseState *state, char *oper,
* Parse PSYC packets. * Parse PSYC packets.
* Generalized line-based parser. * Generalized line-based parser.
*/ */
psycParseRC psyc_parse (psycParseState* state, char* oper, psycParseRC psyc_parse (psycParseState *state, char *oper,
psycString* name, psycString* value) psycString *name, psycString *value)
{ {
#ifdef DEBUG #ifdef DEBUG
if (state->flags & PSYC_PARSE_ROUTING_ONLY && if (state->flags & PSYC_PARSE_ROUTING_ONLY &&
@ -298,7 +298,7 @@ psycParseRC psyc_parse (psycParseState* state, char* oper,
case PSYC_PART_CONTENT: case PSYC_PART_CONTENT:
// In case of an incomplete binary variable resume parsing it. // In case of an incomplete binary variable resume parsing it.
if (state->valueParsed < state->valueLength) if (state->valueParsed < state->valueLength)
{ {
ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed)); ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed));
state->contentParsed += value->length; state->contentParsed += value->length;
@ -453,8 +453,8 @@ psycParseRC psyc_parse (psycParseState* state, char* oper,
* List value parser. * List value parser.
* @return see psycListRC. * @return see psycListRC.
*/ */
psycParseListRC psyc_parseList (psycParseListState* state, psycString *name, psycParseListRC psyc_parseList (psycParseListState *state, psycString *name,
psycString* value, psycString* elem) psycString *value, psycString *elem)
{ {
if (state->cursor >= state->buffer.length) if (state->cursor >= state->buffer.length)
return PSYC_PARSE_LIST_INCOMPLETE; return PSYC_PARSE_LIST_INCOMPLETE;