fixed bug with arrays introduced in commit 9f6d4ab63f

This commit is contained in:
2018-06-19 14:16:28 +02:00
parent 3b26bca69a
commit 1120651daa

View File

@ -586,19 +586,9 @@ ssize_t streamScanfN(dbCommon* record, format_t *format,
void* value, size_t maxStringSize) void* value, size_t maxStringSize)
{ {
ssize_t size; ssize_t size;
debug("streamScanfN(%s,format=%%%c,maxStringSize=%ld)\n",
record->name, format->priv->conv, (long)maxStringSize);
Stream* pstream = (Stream*)record->dpvt; Stream* pstream = (Stream*)record->dpvt;
if (!pstream) return ERROR; if (!pstream) return ERROR;
size = pstream->scan(format, value, maxStringSize); size = pstream->scan(format, value, maxStringSize);
if (size == ERROR)
{
debug("streamScanfN(%s) failed\n", record->name);
}
#ifndef NO_TEMPORARY
debug("streamScanfN(%s) success, value=\"%s\"\n",
record->name, StreamBuffer((char*)value).expand()());
#endif
return size; return size;
} }
@ -828,9 +818,11 @@ print(format_t *format, va_list ap)
return printValue(*format->priv, va_arg(ap, double)); return printValue(*format->priv, va_arg(ap, double));
case DBF_STRING: case DBF_STRING:
return printValue(*format->priv, va_arg(ap, char*)); return printValue(*format->priv, va_arg(ap, char*));
default:
error("INTERNAL ERROR (%s): Illegal format type %d\n",
name(), format->type);
return false;
} }
error("INTERNAL ERROR (%s): Illegal format type\n", name());
return false;
} }
ssize_t Stream:: ssize_t Stream::
@ -839,7 +831,7 @@ scan(format_t *format, void* value, size_t maxStringSize)
// called by streamScanfN // called by streamScanfN
size_t size = maxStringSize; size_t size = maxStringSize;
// first remove old value from inputLine (if we are scanning arrays) // first remove old value from inputLine (in case we are scanning arrays)
consumedInput += currentValueLength; consumedInput += currentValueLength;
currentValueLength = 0; currentValueLength = 0;
switch (format->type) switch (format->type)
@ -853,16 +845,21 @@ scan(format_t *format, void* value, size_t maxStringSize)
currentValueLength = scanValue(*format->priv, *(double*)value); currentValueLength = scanValue(*format->priv, *(double*)value);
break; break;
case DBF_STRING: case DBF_STRING:
currentValueLength = scanValue(*format->priv, (char*)value, currentValueLength = scanValue(*format->priv, (char*)value, size);
size);
break; break;
default: default:
error("INTERNAL ERROR (%s): Illegal format type\n", name()); error("INTERNAL ERROR (%s): Illegal format type %d\n",
name(), format->type);
return ERROR; return ERROR;
} }
debug("Stream::scan() currentValueLength=%" Z "d\n", currentValueLength);
if (currentValueLength < 0)
{
currentValueLength = 0; // important for arrays with less than NELM elements
return ERROR;
}
// Don't remove scanned value from inputLine yet, because // Don't remove scanned value from inputLine yet, because
// we might need the string in a later error message. // we might need the string in a later error message.
if (currentValueLength == ERROR) return ERROR;
if (format->type == DBF_STRING) return size; if (format->type == DBF_STRING) return size;
return OK; return OK;
} }
@ -1442,6 +1439,7 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
} }
flags |= ValueReceived; flags |= ValueReceived;
consumedInput += currentValueLength; consumedInput += currentValueLength;
debug("Stream::matchValue(%s): success, %" Z "d bytes consumed\n", name(), currentValueLength);
return true; return true;
} }