Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
GCC 11 gives -Wstringop-overflow when no string operation is used

Here is my code.

// test.c
#include <stdio.h>

#define ARRAY_SIZE 4

struct example_t {
  int field0;
  int field1;
  int field2;
  int field3;
  int field4;
};

struct example_t func(int *in, int array[ARRAY_SIZE]) {
  struct example_t out;
  return out;
}

int main() {
  int array[ARRAY_SIZE] = { 0, 0, 0, 0 };
  int a = 0;
  struct example_t col = func(&a, array);
  return 0;
}

gcc 11.1.0 gave

$ gcc test.c -o test
test.c: In function ‘main’:
test.c:22:26: warning: ‘func’ accessing 16 bytes in a region of size 4 [-Wstringop-overflow=]
   22 |   struct example_t col = func(&a, array);
      |                          ^~~~~~~~~~~~~~~
test.c:22:26: note: referencing argument 2 of type ‘int *’
test.c:14:18: note: in a call to function ‘func’
   14 | struct example_t func(int *in, int array[ARRAY_SIZE]) {
      |                  ^~~~

but g++ didn't.

I don't understand why the warning message is there, since there is no string operation in my code and I never read array in func.

If there are only 4 or fewer fields in struct example_t, GCC won't complain. Can someone please explain why is the message here and how can i fix it?

Thank you in advance.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda