Message ID | 1350246738-31699-15-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On 10/15/2012 04:32 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > Make mcfg_size a ssize_t and use appropriate printf format > specifiers for this. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/acpi/mcfg/mcfg.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/src/acpi/mcfg/mcfg.c b/src/acpi/mcfg/mcfg.c > index f4cd53c..1655d3b 100644 > --- a/src/acpi/mcfg/mcfg.c > +++ b/src/acpi/mcfg/mcfg.c > @@ -118,7 +118,7 @@ static int mcfg_test1(fwts_framework *fw) > void *mapped_table_page; > struct mcfg_entry *table, firstentry; > int failed = 0; > - int mcfg_size; > + ssize_t mcfg_size; > const char *memory_map_name; > int page_size; > > @@ -148,9 +148,9 @@ static int mcfg_test1(fwts_framework *fw) > mcfg_size -= 36; /* general ACPI header */ > mcfg_size -= 8; /* 8 bytes of padding */ > > - if ((int)mcfg_size<0) { > + if (mcfg_size < 0) { > fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize", > - "Invalid MCFG ACPI table size: got %d bytes expecting more", > + "Invalid MCFG ACPI table size: got %zd bytes expecting more", > mcfg_size + 36 + 8); > fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); > fwts_advice(fw, > @@ -167,14 +167,14 @@ static int mcfg_test1(fwts_framework *fw) > return FWTS_ERROR; > } > > - if ((nr * sizeof(struct mcfg_entry)) != mcfg_size) { > + if (mcfg_size != (ssize_t)(nr * sizeof(struct mcfg_entry))) { > fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize2", > "MCFG table is not a multiple of record size"); > fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); > return FWTS_ERROR; > } > > - fwts_log_info(fw, "MCFG table found, size is %i bytes (excluding header) (%i entries).", > + fwts_log_info(fw, "MCFG table found, size is %zd bytes (excluding header) (%i entries).", > mcfg_size, nr); > > table_page = table_ptr = (const uint8_t *)mcfg_table->data; > Is there a reason ssize_t is more preferred than size_t? Cheers, Alex Hung
On 15/10/12 05:14, Alex Hung wrote: > On 10/15/2012 04:32 AM, Colin King wrote: >> From: Colin Ian King <colin.king@canonical.com> >> >> Make mcfg_size a ssize_t and use appropriate printf format >> specifiers for this. >> >> Signed-off-by: Colin Ian King <colin.king@canonical.com> >> --- >> src/acpi/mcfg/mcfg.c | 10 +++++----- >> 1 file changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/src/acpi/mcfg/mcfg.c b/src/acpi/mcfg/mcfg.c >> index f4cd53c..1655d3b 100644 >> --- a/src/acpi/mcfg/mcfg.c >> +++ b/src/acpi/mcfg/mcfg.c >> @@ -118,7 +118,7 @@ static int mcfg_test1(fwts_framework *fw) >> void *mapped_table_page; >> struct mcfg_entry *table, firstentry; >> int failed = 0; >> - int mcfg_size; >> + ssize_t mcfg_size; >> const char *memory_map_name; >> int page_size; >> >> @@ -148,9 +148,9 @@ static int mcfg_test1(fwts_framework *fw) >> mcfg_size -= 36; /* general ACPI header */ >> mcfg_size -= 8; /* 8 bytes of padding */ >> >> - if ((int)mcfg_size<0) { >> + if (mcfg_size < 0) { >> fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize", >> - "Invalid MCFG ACPI table size: got %d bytes expecting more", >> + "Invalid MCFG ACPI table size: got %zd bytes expecting >> more", >> mcfg_size + 36 + 8); >> fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); >> fwts_advice(fw, >> @@ -167,14 +167,14 @@ static int mcfg_test1(fwts_framework *fw) >> return FWTS_ERROR; >> } >> >> - if ((nr * sizeof(struct mcfg_entry)) != mcfg_size) { >> + if (mcfg_size != (ssize_t)(nr * sizeof(struct mcfg_entry))) { >> fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize2", >> "MCFG table is not a multiple of record size"); >> fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); >> return FWTS_ERROR; >> } >> >> - fwts_log_info(fw, "MCFG table found, size is %i bytes (excluding >> header) (%i entries).", >> + fwts_log_info(fw, "MCFG table found, size is %zd bytes (excluding >> header) (%i entries).", >> mcfg_size, nr); >> >> table_page = table_ptr = (const uint8_t *)mcfg_table->data; >> > > Is there a reason ssize_t is more preferred than size_t? Yep, because the following math on mcfg_size can possibly make it negative: mcfg_size = mcfg_table->length; mcfg_size -= 36; /* general ACPI header */ mcfg_size -= 8; /* 8 bytes of padding */ ..and I'd like to be able to detect that easily. Colin > > Cheers, > Alex Hung >
On 10/15/2012 04:32 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > Make mcfg_size a ssize_t and use appropriate printf format > specifiers for this. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/acpi/mcfg/mcfg.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/src/acpi/mcfg/mcfg.c b/src/acpi/mcfg/mcfg.c > index f4cd53c..1655d3b 100644 > --- a/src/acpi/mcfg/mcfg.c > +++ b/src/acpi/mcfg/mcfg.c > @@ -118,7 +118,7 @@ static int mcfg_test1(fwts_framework *fw) > void *mapped_table_page; > struct mcfg_entry *table, firstentry; > int failed = 0; > - int mcfg_size; > + ssize_t mcfg_size; > const char *memory_map_name; > int page_size; > > @@ -148,9 +148,9 @@ static int mcfg_test1(fwts_framework *fw) > mcfg_size -= 36; /* general ACPI header */ > mcfg_size -= 8; /* 8 bytes of padding */ > > - if ((int)mcfg_size<0) { > + if (mcfg_size < 0) { > fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize", > - "Invalid MCFG ACPI table size: got %d bytes expecting more", > + "Invalid MCFG ACPI table size: got %zd bytes expecting more", > mcfg_size + 36 + 8); > fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); > fwts_advice(fw, > @@ -167,14 +167,14 @@ static int mcfg_test1(fwts_framework *fw) > return FWTS_ERROR; > } > > - if ((nr * sizeof(struct mcfg_entry)) != mcfg_size) { > + if (mcfg_size != (ssize_t)(nr * sizeof(struct mcfg_entry))) { > fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize2", > "MCFG table is not a multiple of record size"); > fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); > return FWTS_ERROR; > } > > - fwts_log_info(fw, "MCFG table found, size is %i bytes (excluding header) (%i entries).", > + fwts_log_info(fw, "MCFG table found, size is %zd bytes (excluding header) (%i entries).", > mcfg_size, nr); > > table_page = table_ptr = (const uint8_t *)mcfg_table->data; > Acked-by: Alex Hung <alex.hung@canonical.com>
On Mon, Oct 15, 2012 at 4:32 AM, Colin King <colin.king@canonical.com> wrote: > From: Colin Ian King <colin.king@canonical.com> > > Make mcfg_size a ssize_t and use appropriate printf format > specifiers for this. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/acpi/mcfg/mcfg.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/src/acpi/mcfg/mcfg.c b/src/acpi/mcfg/mcfg.c > index f4cd53c..1655d3b 100644 > --- a/src/acpi/mcfg/mcfg.c > +++ b/src/acpi/mcfg/mcfg.c > @@ -118,7 +118,7 @@ static int mcfg_test1(fwts_framework *fw) > void *mapped_table_page; > struct mcfg_entry *table, firstentry; > int failed = 0; > - int mcfg_size; > + ssize_t mcfg_size; > const char *memory_map_name; > int page_size; > > @@ -148,9 +148,9 @@ static int mcfg_test1(fwts_framework *fw) > mcfg_size -= 36; /* general ACPI header */ > mcfg_size -= 8; /* 8 bytes of padding */ > > - if ((int)mcfg_size<0) { > + if (mcfg_size < 0) { > fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize", > - "Invalid MCFG ACPI table size: got %d bytes expecting more", > + "Invalid MCFG ACPI table size: got %zd bytes expecting more", > mcfg_size + 36 + 8); > fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); > fwts_advice(fw, > @@ -167,14 +167,14 @@ static int mcfg_test1(fwts_framework *fw) > return FWTS_ERROR; > } > > - if ((nr * sizeof(struct mcfg_entry)) != mcfg_size) { > + if (mcfg_size != (ssize_t)(nr * sizeof(struct mcfg_entry))) { > fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize2", > "MCFG table is not a multiple of record size"); > fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); > return FWTS_ERROR; > } > > - fwts_log_info(fw, "MCFG table found, size is %i bytes (excluding header) (%i entries).", > + fwts_log_info(fw, "MCFG table found, size is %zd bytes (excluding header) (%i entries).", > mcfg_size, nr); > > table_page = table_ptr = (const uint8_t *)mcfg_table->data; > -- > 1.7.10.4 > Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff --git a/src/acpi/mcfg/mcfg.c b/src/acpi/mcfg/mcfg.c index f4cd53c..1655d3b 100644 --- a/src/acpi/mcfg/mcfg.c +++ b/src/acpi/mcfg/mcfg.c @@ -118,7 +118,7 @@ static int mcfg_test1(fwts_framework *fw) void *mapped_table_page; struct mcfg_entry *table, firstentry; int failed = 0; - int mcfg_size; + ssize_t mcfg_size; const char *memory_map_name; int page_size; @@ -148,9 +148,9 @@ static int mcfg_test1(fwts_framework *fw) mcfg_size -= 36; /* general ACPI header */ mcfg_size -= 8; /* 8 bytes of padding */ - if ((int)mcfg_size<0) { + if (mcfg_size < 0) { fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize", - "Invalid MCFG ACPI table size: got %d bytes expecting more", + "Invalid MCFG ACPI table size: got %zd bytes expecting more", mcfg_size + 36 + 8); fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); fwts_advice(fw, @@ -167,14 +167,14 @@ static int mcfg_test1(fwts_framework *fw) return FWTS_ERROR; } - if ((nr * sizeof(struct mcfg_entry)) != mcfg_size) { + if (mcfg_size != (ssize_t)(nr * sizeof(struct mcfg_entry))) { fwts_failed(fw, LOG_LEVEL_HIGH, "MCFGInvalidSize2", "MCFG table is not a multiple of record size"); fwts_tag_failed(fw, FWTS_TAG_ACPI_INVALID_TABLE); return FWTS_ERROR; } - fwts_log_info(fw, "MCFG table found, size is %i bytes (excluding header) (%i entries).", + fwts_log_info(fw, "MCFG table found, size is %zd bytes (excluding header) (%i entries).", mcfg_size, nr); table_page = table_ptr = (const uint8_t *)mcfg_table->data;