1

I declared the following types and function in my program.

typedef char TYPE_name_type;
typedef char TYPE_name_category;
typedef struct {
   TYPE_name_category category;
   TYPE_name_type id;
} TYPE_cod_name;
typedef struct {
   TYPE_name_type name;
   TYPE_cod_name image;
} TYPE_beta_name;
typedef struct {
   TYPE_cod_name lefty;
   TYPE_cod_name righty;
} TYPE_codomain_pair;
typedef char TYPE_thread_ref;
typedef struct {
   TYPE_beta_name items[2];
   unsigned int length;
} TYPE_beta_env;
typedef struct {
   TYPE_thread_ref pid;
   TYPE_beta_env env;
} TYPE_thread_env;
typedef struct {
   TYPE_thread_env items[3];
   unsigned int length;
} TYPE_beta_type;

TYPE_beta_type FUNCTION_post_Reset
(TYPE_beta_type  V34,
 TYPE_thread_ref V35) {
  TYPE_beta_type result;
  TYPE_beta_type V78 = (TYPE__EMPTY_CONST_beta_type);
  TYPE_thread_env V79;
  TYPE_beta_type V79_cont;
  unsigned int V79_index;
  V79_cont = V34;
  V79_index = 0;
  V79 = V79_cont.items[0];
  if (V79_cont.length > 0) {
    while (1) {
      if (V79.pid == V35) {
         V78 = TYPE__OP_thread_env__CONCAT_OP__beta_type(V78, V79);
      }
      if(V79_index == (V79_cont.length - 1)) break;
      V79_index ++;
      V79 = V79_cont.items[V79_index];
      assert (V79.pid == V79_cont.items[V79_index].pid);
    }
  }
  return V78;
}

I noticed that the program sometimes halts at the assert at the end of function right after the struct-to-struct assignment at the previous line. I tried several versions of gcc. It works fine with 4.3.6, 4.7.2 but always fails with 4.6.3.

I am working on a 32-bit Fedora 16 with kernel 3.6.11.

Could it be due to a problem on gcc 4.3.6 or I am overlooking something?

10
  • Eugh. What's with the TYPE_ prefix on everything? Commented Feb 15, 2013 at 9:29
  • Also, what happens when you step through your code with a debugger? Commented Feb 15, 2013 at 9:30
  • The code is very convoluted, and hard to follow, but have you tried running in a debugger? It will stop when the assert fails and you can see the states of variables etc. Commented Feb 15, 2013 at 9:31
  • it's generated code and i use the TYPE_ prefix and ugly variable names to avoid name conflicts. Commented Feb 15, 2013 at 9:32
  • no i haven-t tried to debug it. i'll do that. thanks for the suggestion Commented Feb 15, 2013 at 9:33

1 Answer 1

1

That's the consequence of one of the worst mistakes one can do in programming: using fixed buffer sizes. You are almost guaranteed to run into trouble with it sooner or later, because the requirements will change, and your fixed buffer size will not be enough.

Here the problem is items being only of size 3, and I am certain that you will find V79_index to be 3 upon the failed assert.

Ps: I know that all the world uses fixed buffer sizes. But the whole world once used goto. And I consider both harmful.

Sign up to request clarification or add additional context in comments.

2 Comments

Granted, dynamic buffers are nice, but there are applications where a fixed buffer size cannot be avoided, such as embedded, bare-metal applications that do not support dynamic memory allocation.
@JimFell Right, there is no rule without exception when it comes to programming. Including the rules about goto and fixed buffer sizes... Nevertheless, when you have a choice, avoid both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.