Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

acpi_result_to_string: fix return value which truncated Packages

I misunderstood the manual on the result values of snprintf, it does not
return the number of unwritten bytes (which I expected), but the number
of written bytes or -1 on failure
  • Loading branch information...
commit 45f24c0ceed5c1b2077a5c40a2519104baf93b10 1 parent 7c47a9a
@Lekensteyn Lekensteyn authored
Showing with 7 additions and 4 deletions.
  1. +7 −4 acpi_call.c
View
11 acpi_call.c
@@ -29,10 +29,10 @@ static int acpi_result_to_string(union acpi_object *result) {
int not_written = 0;
if (result->type == ACPI_TYPE_INTEGER) {
- not_written = snprintf(BUFFER, BYTES_AVAIL,
+ snprintf(BUFFER, BYTES_AVAIL,
"0x%x", (int)result->integer.value);
} else if (result->type == ACPI_TYPE_STRING) {
- not_written = snprintf(BUFFER, BYTES_AVAIL,
+ snprintf(BUFFER, BYTES_AVAIL,
"\"%*s\"", result->string.length, result->string.pointer);
} else if (result->type == ACPI_TYPE_BUFFER) {
int i;
@@ -64,12 +64,15 @@ static int acpi_result_to_string(union acpi_object *result) {
break;
}
if (!not_written)
- not_written = snprintf(BUFFER, BYTES_AVAIL, "]");
+ snprintf(BUFFER, BYTES_AVAIL, "]");
} else {
- not_written = snprintf(BUFFER, BYTES_AVAIL,
+ snprintf(BUFFER, BYTES_AVAIL,
"Object type 0x%x\n", result->type);
}
+ if (!not_written && !BYTES_AVAIL)
+ not_written++;
+
return not_written;
#undef BUFFER
#undef BYTES_AVAIL
Please sign in to comment.
Something went wrong with that request. Please try again.