Greetings,

In master version and 4.0 this patch was not applied. Please apply this when 
possible.

Best regards
Jakub Raczynski

> 16.11.2022 20:48 Jacob Keller <jacob.e.kel...@intel.com> wrote:
> 
>  
> When building the tlv.c file, the following warning may occur when
> operating in C89 mode:
> 
>   $make EXTRA_CFLAGS=-std=gnu89
>   tlv.c: In function ‘mgt_post_recv’:
>   tlv.c:374:17: error: ‘for’ loop initial declarations are only allowed in 
> C99 or C11 mode
>     374 |                 for (int i = 0; i < umtn->actual_table_size; i++) {
>         |                 ^~~
>   tlv.c:374:17: note: use option ‘-std=c99’, ‘-std=gnu99’, ‘-std=c11’ or 
> ‘-std=gnu11’ to compile your code
>   tlv.c: In function ‘mgt_pre_send’:
>   tlv.c:551:17: error: ‘for’ loop initial declarations are only allowed in 
> C99 or C11 mode
>     551 |                 for (int i = 0; i < umtn->actual_table_size; i++) {
>         |                 ^~~
>   make: *** [<builtin>: tlv.o] Error 1
>   make: *** Waiting for unfinished jobs....
>   pmc.c: In function ‘pmc_show’:
>   pmc.c:559:17: error: ‘for’ loop initial declarations are only allowed in 
> C99 or C11 mode
>     559 |                 for (int i = 0; i < umtn->actual_table_size; i++) {
>         |                 ^~~
> 
> This occurs because initial loop declarations are only supported in C99 or
> newer. LinuxPTP source still prefers to keep with the GNU C89 convention of
> variables being at the top of the function. Newer versions of GCC have
> begun defaulting to a newer C standard, which explains how these slipped
> in. Note that directly enforcing "-std=c89" does not work because we rely
> on some GNU extensions of C89.
> 
> For the tlv.c file it turns out that the case statements which declare the
> variables in loops already have suitable iterator variables bound at the
> top of the function. For the iterator in pmc_show, we need to add the
> declaration at the top of the function.
> 
> Reported-by: Jakub Raczyński <j.raczyn...@elpromaelectronics.com>
> Signed-off-by: Jacob Keller <jacob.e.kel...@intel.com>
> ---
>  pmc.c | 4 ++--
>  tlv.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/pmc.c b/pmc.c
> index e218ca478c38..4640a64ca8ea 100644
> --- a/pmc.c
> +++ b/pmc.c
> @@ -177,8 +177,8 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
>       struct parentDS *pds;
>       struct portDS *p;
>       struct TLV *tlv;
> +     int action, i;
>       uint8_t *buf;
> -     int action;
>  
>       if (msg_type(msg) == SIGNALING) {
>               pmc_show_signaling(msg, fp);
> @@ -556,7 +556,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
>                       "BM", "identity", "address", "state",
>                       "clockClass", "clockQuality", "offsetScaledLogVariance",
>                       "p1", "p2");
> -             for (int i = 0; i < umtn->actual_table_size; i++) {
> +             for (i = 0; i < umtn->actual_table_size; i++) {
>                       ume = (struct unicast_master_entry *) buf;
>                       pmc_show_unicast_master_entry(ume, fp);
>                       buf += sizeof(*ume) + ume->address.addressLength;
> diff --git a/tlv.c b/tlv.c
> index 1c13460796e5..240e7df01545 100644
> --- a/tlv.c
> +++ b/tlv.c
> @@ -371,7 +371,7 @@ static int mgt_post_recv(struct management_tlv *m, 
> uint16_t data_len,
>               umtn->actual_table_size =
>                       ntohs(umtn->actual_table_size);
>               buf = (uint8_t *) umtn->unicast_masters;
> -             for (int i = 0; i < umtn->actual_table_size; i++) {
> +             for (i = 0; i < umtn->actual_table_size; i++) {
>                       len += sizeof(struct unicast_master_entry);
>                       if (data_len < len)
>                               goto bad_length;
> @@ -548,7 +548,7 @@ static void mgt_pre_send(struct management_tlv *m, struct 
> tlv_extra *extra)
>       case MID_UNICAST_MASTER_TABLE_NP:
>               umtn = (struct unicast_master_table_np *)m->data;
>               buf = (uint8_t *) umtn->unicast_masters;
> -             for (int i = 0; i < umtn->actual_table_size; i++) {
> +             for (i = 0; i < umtn->actual_table_size; i++) {
>                       ume = (struct unicast_master_entry *) buf;
>                       // update pointer before the conversion
>                       buf += sizeof(*ume) + ume->address.addressLength;
> -- 
> 2.38.1.420.g319605f8f00e


_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to