Patchwork [02/10] mtd-tests: io_paral: build error, "variable length strings"

login
register
mail settings
Submitter Brian Norris
Date June 27, 2011, 6:27 p.m.
Message ID <1309199247-19248-3-git-send-email-computersforpeace@gmail.com>
Download mbox | patch
Permalink /patch/102247/
State New
Headers show

Comments

Brian Norris - June 27, 2011, 6:27 p.m.
Some compilers will complain about use of strlen() within a static array
size declaration. For this type of string, "sizeof() - 1" is equivalent
and prevents the build error.

Error:

   io_paral.c:48:13: error: variably modified 'vol_nodes' at file scope

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 tests/ubi-tests/io_paral.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Josh Boyer - June 29, 2011, 1:22 p.m.
On Mon, Jun 27, 2011 at 2:27 PM, Brian Norris
<computersforpeace@gmail.com> wrote:
> Some compilers will complain about use of strlen() within a static array
> size declaration. For this type of string, "sizeof() - 1" is equivalent
> and prevents the build error.
>
> Error:
>
>   io_paral.c:48:13: error: variably modified 'vol_nodes' at file scope

Out of curiosity, which compiler does that?  Newer versions of GCC, or
some other compiler altogether?

josh
Brian Norris - June 29, 2011, 3:45 p.m.
On Wed, Jun 29, 2011 at 6:22 AM, Josh Boyer <jwboyer@gmail.com> wrote:
> On Mon, Jun 27, 2011 at 2:27 PM, Brian Norris
> <computersforpeace@gmail.com> wrote:
>> Some compilers will complain about use of strlen() within a static array
>> size declaration. For this type of string, "sizeof() - 1" is equivalent
>> and prevents the build error.
>>
>> Error:
>>
>>   io_paral.c:48:13: error: variably modified 'vol_nodes' at file scope
>
> Out of curiosity, which compiler does that?  Newer versions of GCC, or
> some other compiler altogether?

I think it's just newer versions of GCC. I found the error on MIPS GCC
on versions 4.5.2 and 4.5.3. It didn't occur on MIPS or x86_64 for
version 4.4.3.

Brian

Patch

diff --git a/tests/ubi-tests/io_paral.c b/tests/ubi-tests/io_paral.c
index 9754a0d..1d9a97c 100644
--- a/tests/ubi-tests/io_paral.c
+++ b/tests/ubi-tests/io_paral.c
@@ -45,7 +45,7 @@  static int vol_size;
 
 static struct ubi_mkvol_request reqests[THREADS_NUM + 1];
 static char vol_name[THREADS_NUM + 1][100];
-static char vol_nodes[THREADS_NUM + 1][strlen(UBI_VOLUME_PATTERN) + 100];
+static char vol_nodes[THREADS_NUM + 1][sizeof(UBI_VOLUME_PATTERN) + 99];
 static unsigned char *wbufs[THREADS_NUM + 1];
 static unsigned char *rbufs[THREADS_NUM + 1];