Message ID | 1334068766-3463-1-git-send-email-colin.king@canonical.com |
---|---|
State | Rejected |
Headers | show |
On 04/10/2012 10:39 PM, Colin King wrote: > From: Colin Ian King<colin.king@canonical.com> > > Signed-off-by: Colin Ian King<colin.king@canonical.com> > --- > src/lib/src/fwts_fileio.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/src/lib/src/fwts_fileio.c b/src/lib/src/fwts_fileio.c > index c0a6f15..66e399f 100644 > --- a/src/lib/src/fwts_fileio.c > +++ b/src/lib/src/fwts_fileio.c > @@ -37,7 +37,7 @@ fwts_list *fwts_file_read(FILE *fp) > return NULL; > > while (fgets(buffer, sizeof(buffer), fp) != NULL) { > - int len = strlen(buffer); > + size_t len = strlen(buffer); > buffer[len-1] = '\0'; /* Chop off "\n" */ > fwts_text_list_append(list, buffer); > } The variable len is only used once. Will it be better to change int len = strlen(buffer); buffer[len-1] = '\0'; /* Chop off "\n" */ to buffer[strlen(buffer) - 1] = '\0'; /* Chop off "\n" */ so we don't need to worry about the type of len?
On 11/04/12 03:19, Alex Hung wrote: > On 04/10/2012 10:39 PM, Colin King wrote: >> From: Colin Ian King<colin.king@canonical.com> >> >> Signed-off-by: Colin Ian King<colin.king@canonical.com> >> --- >> src/lib/src/fwts_fileio.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/src/lib/src/fwts_fileio.c b/src/lib/src/fwts_fileio.c >> index c0a6f15..66e399f 100644 >> --- a/src/lib/src/fwts_fileio.c >> +++ b/src/lib/src/fwts_fileio.c >> @@ -37,7 +37,7 @@ fwts_list *fwts_file_read(FILE *fp) >> return NULL; >> >> while (fgets(buffer, sizeof(buffer), fp) != NULL) { >> - int len = strlen(buffer); >> + size_t len = strlen(buffer); >> buffer[len-1] = '\0'; /* Chop off "\n" */ >> fwts_text_list_append(list, buffer); >> } > The variable len is only used once. > Will it be better to change > int len = strlen(buffer); > buffer[len-1] = '\0'; /* Chop off "\n" */ > to > buffer[strlen(buffer) - 1] = '\0'; /* Chop off "\n" */ > so we don't need to worry about the type of len? > > I'm happy with that suggestion - I will tidy that up and re-submit once I've done my next round of changes.
diff --git a/src/lib/src/fwts_fileio.c b/src/lib/src/fwts_fileio.c index c0a6f15..66e399f 100644 --- a/src/lib/src/fwts_fileio.c +++ b/src/lib/src/fwts_fileio.c @@ -37,7 +37,7 @@ fwts_list *fwts_file_read(FILE *fp) return NULL; while (fgets(buffer, sizeof(buffer), fp) != NULL) { - int len = strlen(buffer); + size_t len = strlen(buffer); buffer[len-1] = '\0'; /* Chop off "\n" */ fwts_text_list_append(list, buffer); }