diff mbox

lib: fwts_args: only handle non-zero length short_names

Message ID 1334067478-812-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King April 10, 2012, 2:17 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_args.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Comments

Alex Hung April 11, 2012, 3:44 a.m. UTC | #1
On 04/10/2012 10:17 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_args.c |    4 ++--
>   1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index 90f3d70..b5ef3e0 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -116,14 +116,14 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[])
>
>   		for (i=0; i<options_table->num_options; i++, n++) {
>   			char *short_name = options_table->options[i].short_name;
> +			size_t len;
>   			
>   			long_options[n].name    = options_table->options[i].long_name;
>   			long_options[n].has_arg = options_table->options[i].has_arg;
>   			long_options[n].flag    = 0;
>   			long_options[n].val     = 0;
>   	
> -			if (short_name != NULL) {
> -				int len = strlen(short_name);
> +			if (short_name&&  (len = strlen(short_name))>  0) {
>   				if (short_options) {
>   					short_options = realloc(short_options,
>   						strlen(short_options) + len + 1);
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin April 11, 2012, 5:13 a.m. UTC | #2
On Wed, Apr 11, 2012 at 11:44 AM, Alex Hung <alex.hung@canonical.com> wrote:
> On 04/10/2012 10:17 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_args.c |    4 ++--
>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
>> index 90f3d70..b5ef3e0 100644
>> --- a/src/lib/src/fwts_args.c
>> +++ b/src/lib/src/fwts_args.c
>> @@ -116,14 +116,14 @@ int fwts_args_parse(fwts_framework *fw, int argc,
>> char * const argv[])
>>
>>                for (i=0; i<options_table->num_options; i++, n++) {
>>                        char *short_name =
>> options_table->options[i].short_name;
>> +                       size_t len;
>>
>>                        long_options[n].name    =
>> options_table->options[i].long_name;
>>                        long_options[n].has_arg =
>> options_table->options[i].has_arg;
>>                        long_options[n].flag    = 0;
>>                        long_options[n].val     = 0;
>>
>> -                       if (short_name != NULL) {
>> -                               int len = strlen(short_name);
>> +                       if (short_name&&  (len = strlen(short_name))>  0)
>> {
>>
>>                                if (short_options) {
>>                                        short_options =
>> realloc(short_options,
>>                                                strlen(short_options) + len
>> + 1);
>
> Acked-by: Alex Hung <alex.hung@canonical.com>
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
index 90f3d70..b5ef3e0 100644
--- a/src/lib/src/fwts_args.c
+++ b/src/lib/src/fwts_args.c
@@ -116,14 +116,14 @@  int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[])
 
 		for (i=0; i<options_table->num_options; i++, n++) {
 			char *short_name = options_table->options[i].short_name;
+			size_t len;
 			
 			long_options[n].name    = options_table->options[i].long_name;
 			long_options[n].has_arg = options_table->options[i].has_arg;
 			long_options[n].flag    = 0;
 			long_options[n].val     = 0;
 	
-			if (short_name != NULL) {
-				int len = strlen(short_name);
+			if (short_name && (len = strlen(short_name)) > 0) {
 				if (short_options) {
 					short_options = realloc(short_options,
 						strlen(short_options) + len + 1);