Dumbest mistake you have ever made

Programming, for all ages and all languages.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Dont laugh, please... hehe ;)

Just yesterday, I had two copies of my bootloader open in 2 different windows via explorer. I kept modifying the new copy, but assembling the old copy... ugh. :oops: ...And I wondered why it wasnt doing what I wanted. :roll:

Probably my worst mistake is crashing my video driver twice writing an OpenGL port for my engine. One of these times, it took Windows with it. (Of course, a reboot fixed both times.)

I cant think of any more yet, but I too make alot of silly mistakes--specially when its late and im tired :)

*sigh*
No body knows your code better than you do.. Unless it's 5 years later and ever you don't understand your own code!
I personally never had any trouble understanding my own code... Even code written 5years ago.

Then again, I always comment it, so thats probably why.
Last edited by neon on Sat Nov 24, 2007 7:34 pm, edited 1 time in total.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

neon wrote: Just yesterday, I had two copies of my bootloader open in 2 different windows via explorer. I kept modifying the new copy, but assembling the old copy... ugh. :oops: ...And I wondered why it wasnt doing what I wanted. :roll:
Hehe, I do that all the time if I need to work without a real source control. :)
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

lol I made one myself today. I couldn't find what the problem was for almost 5 minutes. I had a variable called "Cache" which was defined globally in Delphi like this:

Code: Select all

Cache           : Array [0..MAX_CACHED_LINES-1] of OneLineofText;

Then I wanted to set a pointer to this variable and find the last CR or LF in this buffer like this:

Code: Select all

(* ---------------------------------------- *)
procedure TForm1.Button2Click(Sender: TObject);
Var
  CurrentLine     : Array[0..MAX_STR-1] of Char;
  CurrentLinePtr  : PChar;
  CachePtr        : PChar;
begin
if (PChar(Integer(CachePtr) + (BytesRead-1))^ <> #13) and
   (PChar(Integer(CachePtr) + (BytesRead-1))^ <> #10) then
  begin
    Inc(CachePtr, BytesRead-1);
    While (CachePtr^ <> #13) and (CachePtr^ <> #10) do
      Dec(CachePtr);
  end;
CachePtr^ := #0;
CachePtr := @Cache;
ShowMessage(CachePtr);
end;
(* ---------------------------------------- *)
Well as you can see, I haven't set the "CachePtr" a pointer to the "Cache" variable. So "CachePtr" was pointing to an unknown memory location :roll:
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Well, heres a pretty good one:

I was just debugging my page frame allocation mechanism, because every time I added a new global class to my kernel, important data (such as the GDT) was overwritten. Anyone who has previously been bored of my posts in the past will know that I always say "get stable memory allocation working before anything else".

Anyway, I had written a remove_range(start, length) function to my physical memory allocator. The first thing the allocator does is remove known 'in-use' pages such as the BDA, kernel and so on from the bitmap of free pages. The problem? I had written:

Code: Select all

remove_range(kernelstart, kernelstart - kernelend);
For some odd reason, everything above the start address of the kernel was unavailable for allocation - hopefully, you can see why... #-o

Cheers,
Adam
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

he he he that's a cracker!
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

I tried putting new in the constructor of a global object in my C++ kernel. (It won't work because the constructor would have been called before my memory manager initialised.)
My OS is Perception.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

In a similar vein to AJ's...

Code: Select all

for (int i = USER_HEAP_START; i < USER_HEAP_INITIAL_SIZE; i += PAGE_SIZE)
should have been

Code: Select all

for (int i = USER_HEAP_START; i < USER_HEAP_INITIAL_SIZE+USER_HEAP_START; i += PAGE_SIZE)
Hooray for wraparound! It caused every page from 0xD000000 onwards to be allocated straight away which meant that when fork()ing every other process shared the same set of page tables, meaning my shared objects were being mapped into every address space instead of one!

Wow, that took me a long time to find... :S
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

Okay I don't think this is a programming mistake more than it is a design problem but since it is related to programming I'll put it here. In the design of my file system's boot sector, I have a byte field just before the boot signature that is supposed to keep the checksum. I have written this explanation for this byte-long field:
SSFS Boot Sector's Documentation wrote:Boot Sector’s checksum. This value must be set to the sum of all the bytes in the boot sector (from Byte#0 to Byte#511 inclusive) without the carry bit to make it an 8-bits-long checksum. If this value is not equal to the sum of all 512 bytes of the boot sector, the boot sector’s code located at Byte#0 must detect this error and report it to the user.
Well the problem is that the check-sum byte is one of the bytes in the 512 byte range. So how I have to set this value, I still don't know :lol: I am going to have to exclude Byte# 509 from the checksum
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Thats why most checksums aim for a sum of zero.

Add all other bytes, and calculate how much to need to add to the value to obtain 0x00. Set the checksum as *that value*. Then, any checking program just needs to ensure that the sum of all bytes in the header == 0.

Cheers,
Adam
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

Wow you are right. *slaps himself in the head*. Thank you for pointing this out.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

Well I just considered your suggestion but the problem still exists. Suppose you have three bytes:

Byte#1 = 1
Byte#2 = 2
Byte#3 = 3

Now you have to calculate their checksum and write the result as Byte#2

The checksum will be 256 - (1+2+3) = 256 - 6 = 250

Now the byte order is:

Byte#1 = 1
Byte#2 = 250
Byte#3 = 3

Now if I calculate their sum, it will be 254, and not 0. That's the same problem I was having as before. The checksum field is one of the fields involved in calculating the checksum itself. So if it is changed later, then the checksum won't be correct. I fixed this problem with two solutions:

1) Completely exclude the checksum byte when calculating the checksum.
2) Set the checksum byte to zero initially.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

Setting the checkum byte to zero should suffice. If you add all the values adding a zero should not affect the end result.
Author of COBOS
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Back on topic:

I had in my code:

Code: Select all

SomeStruct *someStruct;

memcpy(... , ... , sizeof(someStruct));
sizeof(someStruct) would return the size of the pointer, not the size of the struct :D.
My OS is Perception.
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Post by Masterkiller »

Code: Select all

...
XOR ah, ah
INT 16 ;Wait for a key press (Should be 16h, not 16)
CMP ah, 1Ch ;Enter pressed?
...
I write the code in the boot sector and boot my PC (not emulator) and get 'out of Horizontal/Vertical Frequency' message from the monitor. It took me about an hour to find the missing 'h'... :D

Other stupid thing I've done :) I test protected mode without loaded IDT and create print_f proc. First instruction of the the proc is PUSHA, but I forget to add POPA instruction before RET, so CPU goes in triple fault :roll: So from now I will test protected mode kernel in Virtual PC :wink:
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post by ucosty »

I have to withdraw my previous entry and post a new one.

I spent ages wondering why I could never get my serial driver working. As it turns out I was casting the port number (for the outport) to a char. The only reason I never noticed before was because all the port numbers I had used fit within a char, unlike the serial ports.

:oops:
The cake is a lie | rackbits.com
Post Reply