[libubootenv] fw_printenv: remove declaration in for loop
diff mbox series

Message ID 1556571742-10733-1-git-send-email-pjtexier@koncepto.io
State Accepted
Headers show
Series
  • [libubootenv] fw_printenv: remove declaration in for loop
Related show

Commit Message

'Chmielewski Andreas' via swupdate April 29, 2019, 9:02 p.m. UTC
This commit fixes :

src/fw_printenv.c:142:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 0; i < argc; i++) {

Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
---
 src/fw_printenv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Stefano Babic April 30, 2019, 6:16 a.m. UTC | #1
Hi Pierre,

On 29/04/19 23:02, 'Pierre-Jean Texier' via swupdate wrote:
> This commit fixes :
> 
> src/fw_printenv.c:142:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
>     for (int i = 0; i < argc; i++) {
> 

In fact, SWUpdate is written in C99. Some constructs are used a lot in
SWUpdate. However, this is a separate project, I have no problem to
apply this - just ask which is your environment. Even old gcc (5.4) has
no problem with it, which is your compiler ?

Best regards,
Stefano Babic

> Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
> ---
>  src/fw_printenv.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/fw_printenv.c b/src/fw_printenv.c
> index 361d150..4236eaa 100644
> --- a/src/fw_printenv.c
> +++ b/src/fw_printenv.c
> @@ -59,7 +59,7 @@ int main (int argc, char **argv) {
>  	char *cfgfname = NULL;
>  	char *defenvfile = NULL;
>  	char *scriptfile = NULL;
> -	int c;
> +	int c, i;
>  	int ret = 0;
>  	void *tmp;
>  	const char *name, *value;
> @@ -139,7 +139,7 @@ int main (int argc, char **argv) {
>  				fprintf(stdout, "%s=%s\n", name, value);
>  			}
>  		} else {
> -			for (int i = 0; i < argc; i++) {
> +			for (i = 0; i < argc; i++) {
>  				value = libuboot_get_env(ctx, argv[i]);
>  				if (noheader)
>  					fprintf(stdout, "%s\n", value ? value : "");
> @@ -151,7 +151,7 @@ int main (int argc, char **argv) {
>  		if (scriptfile)
>  			libuboot_load_file(ctx, scriptfile);
>  		else {
> -			for (int i = 0; i < argc; i += 2) {
> +			for (i = 0; i < argc; i += 2) {
>  				if (i + 1 == argc)
>  					libuboot_set_env(ctx, argv[i], NULL);
>  				else
>
'Chmielewski Andreas' via swupdate April 30, 2019, 3:44 p.m. UTC | #2
Hi Stefano,

Le 30/04/2019 à 08:16, Stefano Babic a écrit :
> In fact, SWUpdate is written in C99. Some constructs are used a lot in
> SWUpdate. However, this is a separate project, I have no problem to
> apply this - just ask which is your environment. Even old gcc (5.4) has
> no problem with it, which is your compiler ?
>
> Best regards,
> Stefano Babic

Indeed, the GCC is quiet old (4.9) :

br-arm-full-2019.02-rc1/usr/bin/arm-buildroot-linux-uclibcgnueabi-gcc -v

<..>
gcc version 4.9.4 (Buildroot 2019.02-rc1)


In fact, the problem appeared during integration in Buildroot, especially
with the following test (see [1]) :

$: ./utils/test-pkg -c libubootenv.config -p libubootenv ,
and the build fails with the "*br-arm-ful*l" configuration [2].


Thanks
Pierre-Jean

[1] 
https://github.com/buildroot/buildroot/blob/master/docs/manual/adding-packages-tips.txt#L123 
<https://github.com/buildroot/buildroot/blob/d9d47b20b55268e8f9897dd2f40325f6c907b2da/docs/manual/adding-packages-tips.txt#L109>
[2] 
https://github.com/buildroot/buildroot/blob/master/support/config-fragments/autobuild/br-arm-full.config
>> Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
>> ---
>>   src/fw_printenv.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/fw_printenv.c b/src/fw_printenv.c
>> index 361d150..4236eaa 100644
>> --- a/src/fw_printenv.c
>> +++ b/src/fw_printenv.c
>> @@ -59,7 +59,7 @@ int main (int argc, char **argv) {
>>   	char *cfgfname = NULL;
>>   	char *defenvfile = NULL;
>>   	char *scriptfile = NULL;
>> -	int c;
>> +	int c, i;
>>   	int ret = 0;
>>   	void *tmp;
>>   	const char *name, *value;
>> @@ -139,7 +139,7 @@ int main (int argc, char **argv) {
>>   				fprintf(stdout, "%s=%s\n", name, value);
>>   			}
>>   		} else {
>> -			for (int i = 0; i < argc; i++) {
>> +			for (i = 0; i < argc; i++) {
>>   				value = libuboot_get_env(ctx, argv[i]);
>>   				if (noheader)
>>   					fprintf(stdout, "%s\n", value ? value : "");
>> @@ -151,7 +151,7 @@ int main (int argc, char **argv) {
>>   		if (scriptfile)
>>   			libuboot_load_file(ctx, scriptfile);
>>   		else {
>> -			for (int i = 0; i < argc; i += 2) {
>> +			for (i = 0; i < argc; i += 2) {
>>   				if (i + 1 == argc)
>>   					libuboot_set_env(ctx, argv[i], NULL);
>>   				else
>>
Stefano Babic April 30, 2019, 3:50 p.m. UTC | #3
Hallo Pierre,

On 30/04/19 17:44, Pierre-Jean Texier wrote:
> Hi Stefano,
> 
> Le 30/04/2019 à 08:16, Stefano Babic a écrit :
>> In fact, SWUpdate is written in C99. Some constructs are used a lot in
>> SWUpdate. However, this is a separate project, I have no problem to
>> apply this - just ask which is your environment. Even old gcc (5.4) has
>> no problem with it, which is your compiler ?
>>
>> Best regards,
>> Stefano Babic
> 
> Indeed, the GCC is quiet old (4.9) :
> 
> br-arm-full-2019.02-rc1/usr/bin/arm-buildroot-linux-uclibcgnueabi-gcc -v
> 
> <..>
> gcc version 4.9.4 (Buildroot 2019.02-rc1)
> 
> 
> In fact, the problem appeared during integration in Buildroot, especially
> with the following test (see [1]) :
> 
> $: ./utils/test-pkg -c libubootenv.config -p libubootenv ,
> and the build fails with the "*br-arm-ful*l" configuration [2].
> 

ok - I can merge the patch, as this is the single point with
compatibility issues. Nevertheless, I will tend in future to use or
accept patches that comply to C99, as it was discussed previously for
SWUpdate.

Regards,
Stefano

> 
> Thanks
> Pierre-Jean
> 
> [1]
> https://github.com/buildroot/buildroot/blob/master/docs/manual/adding-packages-tips.txt#L123
> <https://github.com/buildroot/buildroot/blob/d9d47b20b55268e8f9897dd2f40325f6c907b2da/docs/manual/adding-packages-tips.txt#L109>
> [2]
> https://github.com/buildroot/buildroot/blob/master/support/config-fragments/autobuild/br-arm-full.config
>>> Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
>>> ---
>>>  src/fw_printenv.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/src/fw_printenv.c b/src/fw_printenv.c
>>> index 361d150..4236eaa 100644
>>> --- a/src/fw_printenv.c
>>> +++ b/src/fw_printenv.c
>>> @@ -59,7 +59,7 @@ int main (int argc, char **argv) {
>>>  	char *cfgfname = NULL;
>>>  	char *defenvfile = NULL;
>>>  	char *scriptfile = NULL;
>>> -	int c;
>>> +	int c, i;
>>>  	int ret = 0;
>>>  	void *tmp;
>>>  	const char *name, *value;
>>> @@ -139,7 +139,7 @@ int main (int argc, char **argv) {
>>>  				fprintf(stdout, "%s=%s\n", name, value);
>>>  			}
>>>  		} else {
>>> -			for (int i = 0; i < argc; i++) {
>>> +			for (i = 0; i < argc; i++) {
>>>  				value = libuboot_get_env(ctx, argv[i]);
>>>  				if (noheader)
>>>  					fprintf(stdout, "%s\n", value ? value : "");
>>> @@ -151,7 +151,7 @@ int main (int argc, char **argv) {
>>>  		if (scriptfile)
>>>  			libuboot_load_file(ctx, scriptfile);
>>>  		else {
>>> -			for (int i = 0; i < argc; i += 2) {
>>> +			for (i = 0; i < argc; i += 2) {
>>>  				if (i + 1 == argc)
>>>  					libuboot_set_env(ctx, argv[i], NULL);
>>>  				else
>>>
'Chmielewski Andreas' via swupdate April 30, 2019, 5:07 p.m. UTC | #4
Stefano,

Le 30/04/2019 à 17:50, Stefano Babic a écrit :
> ok - I can merge the patch, as this is the single point with
> compatibility issues. Nevertheless, I will tend in future to use or
> accept patches that comply to C99, as it was discussed previously for
> SWUpdate.
>
> Regards,
> Stefano


Sure, I understand.

Thanks


Regards

Pierre-Jean

>
>> Thanks
>> Pierre-Jean
>>
>> [1]
>> https://github.com/buildroot/buildroot/blob/master/docs/manual/adding-packages-tips.txt#L123
>> <https://github.com/buildroot/buildroot/blob/d9d47b20b55268e8f9897dd2f40325f6c907b2da/docs/manual/adding-packages-tips.txt#L109>
>> [2]
>> https://github.com/buildroot/buildroot/blob/master/support/config-fragments/autobuild/br-arm-full.config
>>>> Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
>>>> ---
>>>>   src/fw_printenv.c | 6 +++---
>>>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/src/fw_printenv.c b/src/fw_printenv.c
>>>> index 361d150..4236eaa 100644
>>>> --- a/src/fw_printenv.c
>>>> +++ b/src/fw_printenv.c
>>>> @@ -59,7 +59,7 @@ int main (int argc, char **argv) {
>>>>   	char *cfgfname = NULL;
>>>>   	char *defenvfile = NULL;
>>>>   	char *scriptfile = NULL;
>>>> -	int c;
>>>> +	int c, i;
>>>>   	int ret = 0;
>>>>   	void *tmp;
>>>>   	const char *name, *value;
>>>> @@ -139,7 +139,7 @@ int main (int argc, char **argv) {
>>>>   				fprintf(stdout, "%s=%s\n", name, value);
>>>>   			}
>>>>   		} else {
>>>> -			for (int i = 0; i < argc; i++) {
>>>> +			for (i = 0; i < argc; i++) {
>>>>   				value = libuboot_get_env(ctx, argv[i]);
>>>>   				if (noheader)
>>>>   					fprintf(stdout, "%s\n", value ? value : "");
>>>> @@ -151,7 +151,7 @@ int main (int argc, char **argv) {
>>>>   		if (scriptfile)
>>>>   			libuboot_load_file(ctx, scriptfile);
>>>>   		else {
>>>> -			for (int i = 0; i < argc; i += 2) {
>>>> +			for (i = 0; i < argc; i += 2) {
>>>>   				if (i + 1 == argc)
>>>>   					libuboot_set_env(ctx, argv[i], NULL);
>>>>   				else
>>>>
>
Stefano Babic May 17, 2019, 8:41 a.m. UTC | #5
On 29/04/19 23:02, 'Pierre-Jean Texier' via swupdate wrote:
> This commit fixes :
> 
> src/fw_printenv.c:142:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
>     for (int i = 0; i < argc; i++) {
> 
> Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
> ---
>  src/fw_printenv.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/fw_printenv.c b/src/fw_printenv.c
> index 361d150..4236eaa 100644
> --- a/src/fw_printenv.c
> +++ b/src/fw_printenv.c
> @@ -59,7 +59,7 @@ int main (int argc, char **argv) {
>  	char *cfgfname = NULL;
>  	char *defenvfile = NULL;
>  	char *scriptfile = NULL;
> -	int c;
> +	int c, i;
>  	int ret = 0;
>  	void *tmp;
>  	const char *name, *value;
> @@ -139,7 +139,7 @@ int main (int argc, char **argv) {
>  				fprintf(stdout, "%s=%s\n", name, value);
>  			}
>  		} else {
> -			for (int i = 0; i < argc; i++) {
> +			for (i = 0; i < argc; i++) {
>  				value = libuboot_get_env(ctx, argv[i]);
>  				if (noheader)
>  					fprintf(stdout, "%s\n", value ? value : "");
> @@ -151,7 +151,7 @@ int main (int argc, char **argv) {
>  		if (scriptfile)
>  			libuboot_load_file(ctx, scriptfile);
>  		else {
> -			for (int i = 0; i < argc; i += 2) {
> +			for (i = 0; i < argc; i += 2) {
>  				if (i + 1 == argc)
>  					libuboot_set_env(ctx, argv[i], NULL);
>  				else
> 

Applied to -master, thanks !

Best regards,
Stefano Babic

Patch
diff mbox series

diff --git a/src/fw_printenv.c b/src/fw_printenv.c
index 361d150..4236eaa 100644
--- a/src/fw_printenv.c
+++ b/src/fw_printenv.c
@@ -59,7 +59,7 @@  int main (int argc, char **argv) {
 	char *cfgfname = NULL;
 	char *defenvfile = NULL;
 	char *scriptfile = NULL;
-	int c;
+	int c, i;
 	int ret = 0;
 	void *tmp;
 	const char *name, *value;
@@ -139,7 +139,7 @@  int main (int argc, char **argv) {
 				fprintf(stdout, "%s=%s\n", name, value);
 			}
 		} else {
-			for (int i = 0; i < argc; i++) {
+			for (i = 0; i < argc; i++) {
 				value = libuboot_get_env(ctx, argv[i]);
 				if (noheader)
 					fprintf(stdout, "%s\n", value ? value : "");
@@ -151,7 +151,7 @@  int main (int argc, char **argv) {
 		if (scriptfile)
 			libuboot_load_file(ctx, scriptfile);
 		else {
-			for (int i = 0; i < argc; i += 2) {
+			for (i = 0; i < argc; i += 2) {
 				if (i + 1 == argc)
 					libuboot_set_env(ctx, argv[i], NULL);
 				else