Home  |  Forums  |  914 Info  |  Blogs
 
914World.com - The fastest growing online 914 community!
 
Porsche, and the Porsche crest are registered trademarks of Dr. Ing. h.c. F. Porsche AG. This site is not affiliated with Porsche in any way.
Its only purpose is to provide an online forum for car enthusiasts. All other trademarks are property of their respective owners.
 

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> WOT: ARRGGHHH, i hate fixing someone elses code!, F%^$SH*&@@@
SirAndy
post Aug 15 2005, 07:33 PM
Post #1


Resident German
*************************

Group: Admin
Posts: 41,618
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



this was supposed to be a simple stripped down BASE64 decoder done in java.

i don't (can't) use a lot of standard libraries because this App will be run on PDAs and java enabled cellphones, so SIZE does matter.

no problem, i get one of my contractors the BASE64 specs and some sample implementations ...

he's been fighting with this for 3 days now so i get his sourcefile and have a look at it this morning.
looks OK at first glance, but when you run it, it sporadically spits out wrong bytevalues while some decode just fine.
wtf?
so i spend all day going through his code (which is not that much) and i just can't figure out what's wrong.

then finally, about 15 minutes ago it dawns on me, have a look at this:

bReturn2[nn+2] = (byte)(iRes % 0xFF);
bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF);
bReturn2[nn+0] = (byte)((iRes >> 16) % 0xFF);


bReturn2 is a byte array, iRes a integer, the purpose is to roll the lower 3 bytes of the integer into 3 sequential fields in the byte array.

i had been staring at this for 6 hours and couldn't figure out what was wrong.
all the while it was right in front of me, plain sight, right there ... (IMG:http://www.914world.com/bbs2/html/emoticons/headbang.gif)

can you find the error?
(IMG:http://www.914world.com/bbs2/html/emoticons/idea.gif) Andy

PS: did i mention that i HATE going through someone else code?
User is online!Profile CardPM
Go to the top of the page
+Quote Post
SpecialK
post Aug 15 2005, 08:02 PM
Post #2


aircraft surgeon
****

Group: Benefactors
Posts: 3,211
Joined: 15-March 04
From: Pacific, MO
Member No.: 1,797



I have NFI, but I'd guess you're missing a parenthesis in the first line........but then again....I have NFI. (IMG:http://www.914world.com/bbs2/html/emoticons/confused24.gif)

Get your broken off allen wrench out?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Midtowner
post Aug 15 2005, 08:15 PM
Post #3


Ooooo!
***

Group: Members
Posts: 652
Joined: 21-December 04
From: Sunnyvale, CA
Member No.: 3,316
Region Association: None



Sounds all Japanese to me! (IMG:http://www.914world.com/bbs2/html/emoticons/smile.gif)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Joe Bob
post Aug 15 2005, 08:27 PM
Post #4


Retired admin, banned a few times
***************

Group: Members
Posts: 17,427
Joined: 24-December 02
From: Boulder CO
Member No.: 5
Region Association: None



Or ya got extra ones....parenthesis that is....
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Foxman
post Aug 15 2005, 08:29 PM
Post #5


Member
**

Group: Members
Posts: 57
Joined: 17-March 05
From: Fort Worth, TX
Member No.: 3,778



bReturn2[nn+2] = (byte)(iRes % 0xFF);

What are you calculating the remainder of? Are you dividing iRes and 0XFF somewhere else? It is hard to say without seeing the rest of the function.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
johnmhudson111
post Aug 15 2005, 08:29 PM
Post #6


Member
**

Group: Members
Posts: 491
Joined: 29-November 04
From: Nesbit, MS
Member No.: 3,191



QUOTE (Buzzard1 @ Aug 15 2005, 09:02 PM)
I'd guess you're missing a parenthesis in the first line.......

(IMG:http://www.914world.com/bbs2/html/emoticons/agree.gif) Just a WAG since I have no coding ability, just an analyst by nature and that seems to be the missing pattern.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Aug 15 2005, 08:32 PM
Post #7


Resident German
*************************

Group: Admin
Posts: 41,618
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (johnmhudson111 @ Aug 15 2005, 07:29 PM)
Just a WAG since I have no coding ability, just an analyst by nature and that seems to be the missing pattern.

nope, nothing missing, syntax is just fine, compiles and runs without an error ...

(IMG:http://www.914world.com/bbs2/html/emoticons/wink.gif) Andy
User is online!Profile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Aug 15 2005, 08:35 PM
Post #8


Resident German
*************************

Group: Admin
Posts: 41,618
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (Foxman @ Aug 15 2005, 07:29 PM)
What are you calculating the remainder of? Are you dividing iRes and 0XFF somewhere else? It is hard to say without seeing the rest of the function.

this takes a 4 byte integer and zeros out all bits except the lowest 8 (0xff) and then stores those 8 bit in an byte-array.

1st line has no shift to get 1st byte
2nd line has 8 bit shift to get 2nd byte
3rd line has 16 bit shift to get 3rd byte

that all is correct, but he still managed to f&%$ it up ...
(IMG:http://www.914world.com/bbs2/html/emoticons/dry.gif) Andy
User is online!Profile CardPM
Go to the top of the page
+Quote Post
johnmhudson111
post Aug 15 2005, 08:36 PM
Post #9


Member
**

Group: Members
Posts: 491
Joined: 29-November 04
From: Nesbit, MS
Member No.: 3,191



QUOTE (SirAndy @ Aug 15 2005, 09:32 PM)
nope, nothing missing, syntax is just fine, compiles and runs without an error ...

(IMG:http://www.914world.com/bbs2/html/emoticons/wink.gif) Andy

bReturn2[nn+2] = (byte)((iRes >> 4) % 0xFF);
bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF);
bReturn2[nn+0] = (byte)((iRes >> 16) % 0xFF);

Nother WAG, I give up after this one (IMG:http://www.914world.com/bbs2/html/emoticons/happy11.gif)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
jonwatts
post Aug 15 2005, 08:37 PM
Post #10


no rules, just wrong
****

Group: Benefactors
Posts: 2,321
Joined: 13-January 03
From: San Jose, CA
Member No.: 141



I would have used the '&' operator instead of the '%' operator, but that's just me.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
r_towle
post Aug 15 2005, 08:58 PM
Post #11


Custom Member
***************

Group: Members
Posts: 24,572
Joined: 9-January 03
From: Taxachusetts
Member No.: 124
Region Association: North East States



QUOTE (SirAndy @ Aug 15 2005, 08:33 PM)
this was supposed to be a simple stripped down BASE64 decoder done in java.

i don't (can't) use a lot of standard libraries because this App will be run on PDAs and java enabled cellphones, so SIZE does matter.

no problem, i get one of my contractors the BASE64 specs and some sample implementations ...

he's been fighting with this for 3 days now so i get his sourcefile and have a look at it this morning.
looks OK at first glance, but when you run it, it sporadically spits out wrong bytevalues while some decode just fine.
wtf?
so i spend all day going through his code (which is not that much) and i just can't figure out what's wrong.

then finally, about 15 minutes ago it dawns on me, have a look at this:

bReturn2[nn+2] = (byte)(iRes % 0xFF);
bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF);
bReturn2[nn+0] = (byte)((iRes >> 16) % 0xFF);


bReturn2 is a byte array, iRes a integer, the purpose is to roll the lower 3 bytes of the integer into 3 sequential fields in the byte array.

i had been staring at this for 6 hours and couldn't figure out what was wrong.
all the while it was right in front of me, plain sight, right there ... (IMG:http://www.914world.com/bbs2/html/emoticons/headbang.gif)

can you find the error?
(IMG:http://www.914world.com/bbs2/html/emoticons/idea.gif) Andy

PS: did i mention that i HATE going through someone else code?

bReturn2[nn+0] = (byte)(iRes % 0xFF);
bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF);
bReturn2[nn+2] = (byte)((iRes >> 16) % 0xFF);
User is online!Profile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Aug 15 2005, 09:07 PM
Post #12


Resident German
*************************

Group: Admin
Posts: 41,618
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (jonwatts @ Aug 15 2005, 07:37 PM)
I would have used the '&' operator instead of the '%' operator, but that's just me.

we've got a winner! (IMG:http://www.914world.com/bbs2/html/emoticons/smilie_pokal.gif)

he used the "%" operator which is MODULO instead of "&" which is bitwise AND ...

took me 6 friggin hours to find that one!
(IMG:http://www.914world.com/bbs2/html/emoticons/headbang.gif) Andy

here's the correct code snippet:

bReturn2[nn+2] = (byte)(iRes & 0xFF);
bReturn2[nn+1] = (byte)((iRes >> 8) & 0xFF);
bReturn2[nn+0] = (byte)((iRes >> 16) & 0xFF);
User is online!Profile CardPM
Go to the top of the page
+Quote Post
jonwatts
post Aug 15 2005, 09:07 PM
Post #13


no rules, just wrong
****

Group: Benefactors
Posts: 2,321
Joined: 13-January 03
From: San Jose, CA
Member No.: 141



Dumb question. Is your input base10 or base16? It doesn't matter to the compiler but it makes a difference to us humans.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
ematulac
post Aug 15 2005, 09:08 PM
Post #14


914 addict
***

Group: Members
Posts: 540
Joined: 24-November 03
From: Palmdale, CA
Member No.: 1,382



edit: nevermind ... modulus looked strange to me there, but it didn't register.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
jonwatts
post Aug 15 2005, 09:09 PM
Post #15


no rules, just wrong
****

Group: Benefactors
Posts: 2,321
Joined: 13-January 03
From: San Jose, CA
Member No.: 141



WOW, and I am such a suck-ass programmer too, but I do have to live in byte-stream land on a daily basis so maybe that helps.

I'd like to thank the Academy, my agent, and Andy for the beautiful 944 CV's, axles, and powder coated trailing arms (or do I just win an attaboy?).

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Aug 15 2005, 09:10 PM
Post #16


Resident German
*************************

Group: Admin
Posts: 41,618
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (ematulac @ Aug 15 2005, 08:08 PM)
He's storing the bytes in the wrong order in the array.

nope, java integer is reverse byte order, so that part was correct ...

jon nailed it, see post above!
(IMG:http://www.914world.com/bbs2/html/emoticons/type.gif) Andy
User is online!Profile CardPM
Go to the top of the page
+Quote Post
Foxman
post Aug 15 2005, 09:12 PM
Post #17


Member
**

Group: Members
Posts: 57
Joined: 17-March 05
From: Fort Worth, TX
Member No.: 3,778



damn, I never thought about the input.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 4th May 2024 - 08:06 PM