Stupidest Programming Mistakes?

Posts you want to find years later go here.
Post Reply
VLSmooth
Tenth Dan Procrastinator
Posts: 3055
Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:

Stupidest Programming Mistakes?

Post by VLSmooth »

Code: Select all

// debug: print out vector
for (vector<int>::iterator iter = someVector.begin();
     iter != someOtherVector.end();
     ++iter) {
  printf("%d\n", *iter);
}
Anyone see a problem? I feel extremely stupid right now... (took 2.5 days to track down...)

Example has been intentionally generalized with extra vagueness
Last edited by VLSmooth on Fri Mar 05, 2004 5:58 pm, edited 1 time in total.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

I don't see what's wrong with the code, some time you need to know where the value is point to :?

VLSmooth
Tenth Dan Procrastinator
Posts: 3055
Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:

Post by VLSmooth »

Notice

Code: Select all

someVector.begin();
and

Code: Select all

someOtherVector.end();
I intended to print out all the elements in someVector...

more background:
someVector = class attribute
someOtherVector = input parameter (was a vector)

Granted, this was one error in 52 files I modified...

* VLSmooth smacks himself again

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

Code: Select all

	SQLBindCol(sql_h_list_stmt, 1, SQL_C_TCHAR, &rate_table_name, 64*tchar_size, &dummy);
	SQLBindCol(sql_h_list_stmt, 2, SQL_C_SHORT, &rate_table_code, 0, &dummy);
	SQLBindCol(sql_h_list_stmt, 3, SQL_C_SHORT, &age_size, 0, &dummy);
	SQLBindCol(sql_h_list_stmt, 4, SQL_C_SHORT, &dur_size, 0, &dummy);

	sql_query = L"SELECT rate_table_code, rate_table_name, age, duration FROM lRateTableList;";
... :(

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

age_size is not the same as age and dur_size is not the same as duration?

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

(rate_table_name, rate_table_code) ordering between the bind and actual select statment

took me 3 hours ...

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

I don't think anyone will be able to catch this one, because the bug is in the intentions of the programmer, not the code.

Original:

Code: Select all

mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0));
I tried to add the possibility of a two_bit_overlap.

Changed to:

Code: Select all

mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0) - (two_bit_overlap ? 1 : 0));

quantus
Tenth Dan Procrastinator
Posts: 4891
Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA

Post by quantus »

Dwindlehop wrote:I don't think anyone will be able to catch this one, because the bug is in the intentions of the programmer, not the code.

Original:

Code: Select all

mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0));
I tried to add the possibility of a two_bit_overlap.

Changed to:

Code: Select all

mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? 1 : 0) - (two_bit_overlap ? 1 : 0));
Ok, lemme guess, you thought you were using one-hot coding when you implemented the part determining what to set one_bit_overlap and two_bit_overlap to. Meanwhile, you are checking it in such a way that if two_bit_overlap is set, one_bit_overlap is expected to be set as well. So in short, you didn't keep your coding schemes in sink? Is that about right?
Have you clicked today? Check status, then: People, Jobs or Roads

VLSmooth
Tenth Dan Procrastinator
Posts: 3055
Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:

Post by VLSmooth »

In short, did you want this?

Code: Select all

mask = generate_mask(num_bits)<<(bits_used - (two_bit_overlap ? 2 : (one_bit_overlap ? 1 : 0)));
In other words,

Code: Select all

if (two_bit_overlap) {
  return 2;
} else if (one_bit_overlap) {
  return 1;
} else {
  return 0;
}
Since, as Joe also pointed out, you never guaranteed the status of one_bit_overlap when two_bit_overlap is set.

ps. Intentions of the programmer equates to your semantics correct? (Which aren't given, hence it's impossible to determine if we're correct, on even on track. whee~)

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

Impressive.

That is largely correct. two_bit_overlap only has meaning if one_bit_overlap is asserted. When one_bit_overlap is false and two_bit_overlap is true, the correct behavior is to have zero overlap.

I had to run a regression to catch that one.

VLSmooth
Tenth Dan Procrastinator
Posts: 3055
Joined: Fri Jul 18, 2003 3:02 am
Location: Varies
Contact:

Post by VLSmooth »

Ah, so:

Code: Select all

mask = generate_mask(num_bits)<<(bits_used - (one_bit_overlap ? (two_bit_overlap ? 2 : 1) : 0));

Code: Select all

if (one_bit_overlap) {
  if (two_bit_overlap) {
    return 2;
  } else {
    return 1;
  }
} else {
  return 0;
}

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

Indeed.

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

Code: Select all

#define FOO 0x7
int bar = FOO&x;
I still can't figure out why this makes bar = 7 for all values of x that I tested.

quantus
Tenth Dan Procrastinator
Posts: 4891
Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA

Post by quantus »

what values of x did you test? 7,15,47, etc?
Have you clicked today? Check status, then: People, Jobs or Roads

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

outputs of a function.

Post Reply