Patchwork lib: fwts_fileio.c: use size_t instead of int

login
register
mail settings
Submitter Colin King
Date April 10, 2012, 2:39 p.m.
Message ID <1334068766-3463-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/151604/
State Rejected
Headers show

Comments

Colin King - April 10, 2012, 2:39 p.m.
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(-)
Alex Hung - April 11, 2012, 2:19 a.m.
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?
Colin King - April 11, 2012, 7:56 a.m.
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.

Patch

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);
 	}