Skip to content

Commit

Permalink
Fix in parser.c
Browse files Browse the repository at this point in the history
Fixed problem with buffer overflow when returning floating point values. Also increased buffer size for parsing floating point values.
  • Loading branch information
b-swat authored Jun 14, 2024
1 parent 59c4229 commit 6033a46
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libscpi/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ size_t SCPI_ResultUInt64Base(scpi_t * context, uint64_t val, int8_t base) {
* @return
*/
size_t SCPI_ResultFloat(scpi_t * context, float val) {
char buffer[32];
char buffer[128];
size_t result = 0;
size_t len = SCPI_FloatToStr(val, buffer, sizeof (buffer));
result += writeDelimiter(context);
Expand All @@ -543,7 +543,7 @@ size_t SCPI_ResultFloat(scpi_t * context, float val) {
* @return
*/
size_t SCPI_ResultDouble(scpi_t * context, double val) {
char buffer[32];
char buffer[128];
size_t result = 0;
size_t len = SCPI_DoubleToStr(val, buffer, sizeof (buffer));
result += writeDelimiter(context);
Expand Down Expand Up @@ -715,10 +715,10 @@ static size_t resultBufferFloatAscii(scpi_t * context, const float *data, size_t
result += writeData(context, "{", 1);

size_t i;
char buffer[32];
char buffer[128];
int ptr = 0;
for (i = 0; i < size; i++) {
sprintf(buffer,"%f%s",data[i],(i < size-1 ? ",":""));
snprintf(buffer,128,"%f%s",data[i],(i < size-1 ? ",":""));
result += writeData(context, buffer, strlen(buffer));
}
result += writeData(context, "}", 1);
Expand Down

0 comments on commit 6033a46

Please sign in to comment.