Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zombywuf
Mar 29, 2008

biznatchio posted:

Yeah maaaan if you're going to be helping spammers out, the least you could do is validate their email address list for RFC compliance for them first.

Exactly.

On another note, I just wrote this:
code:
Sequence = Row_Number() over (
order by
	aar.Direct DESC,
		CASE
			WHEN (
				SELECT
					Count(*)
				FROM
					tbAirports a
				WHERE
					a.CityID = p.iCityID
					and a.HasAnyFlights = 1) > 1
			THEN
				iL.Name
			ELSE
				(SELECT
					ln.[Name]
				FROM
					tbAirports a
					inner join tbLanguageNames ln
						ON a.AirportID = ln.[Id]
				WHERE
					a.CityID = p.iCityID
					and a.HasAnyFlights = 1
					and ln.LanguageID = @LanguageID)
		END ASC),

Adbot
ADBOT LOVES YOU

megalodong
Mar 11, 2008

One of our clients uses vTiger as their CRM program, and I've been saddled with the task of adding things to it that they want.
php:
<?
$rec_type = $_REQUEST["type"];
...
} elseif ($rec_type == "email_addy") {
                $email1 = $_REQUEST["email_addy"];
        }

        $smarty->assign('TO_MAIL',trim($email1,",").",");
?>
Oh dear I hope they're not going to just echo $email1 into the HTML later on they wouldn't do that would they what if someone put
pre:
&type=email_addy&email_addy="><script>myEvilCode();</script>
onto the end of the URL...

code:
<td class="cellText" style="padding: 5px;">
        <input name="{$elements.2.0}" id="{$elements.2.0}" type="hidden" value="{$IDLISTS}">
        <input type="hidden" name="saved_toid" value="{$TO_MAIL}">
        <input id="parent_name" name="parent_name" readonly class="txtBox" type="text" 
value="{$TO_MAIL}" style="width: 550px;">
:sigh: at least it's not internet-facing. And it's still in the latest version of the bloody program.

Actually just imagine I pasted the entire vTiger codebase here because god drat that program is the biggest pile of poo poo ever.

Like when they do something like this:
php:
<?
if($errormessage==2)
{
        $msg =$mod_strings['LBL_MAXIMUM_LIMIT_ERROR'];
        $errormessage ="<B><font color='red'>".$msg."</font></B> <br><br>";
}
else if($errormessage==3)
{
        $msg = $mod_strings['LBL_UPLOAD_ERROR'];
        $errormessage ="<B><font color='red'>".$msg."</font></B> <br><br>";

}
else if($errormessage=="image")
{
        $msg = $mod_strings['LBL_IMAGE_ERROR'];
        $errormessage ="<B><font color='red'>".$msg."</font></B> <br><br>";
}
else if($errormessage =="invalid")
{
        $msg = $mod_strings['LBL_INVALID_IMAGE'];
        $errormessage ="<B><font color='red'>".$msg."</font></B> <br><br>";
}
else
{
        $errormessage="";
}
?>
Apparently "2" and "3" are better than "maximum_limit" and "upload" but "4" isn't better than "image" :confused:

Or
php:
<?
// This function doesn't seem to be used anywhere. Need to check and remove it.
function get_contacts1($user_name,$email_address)
        {
        ...
        }

function get_contacts($user_name,$from_index,$offset)
    {
?>

megalodong fucked around with this message at 04:41 on Oct 9, 2009

geetee
Feb 2, 2004

>;[
And to think all they had to do was:
code:
{$TO_MAIL|escape}

West4th
May 29, 2006
Mediterranean
if(isBagInside==FALSE)
bReady =TRUE ;
else if(isBagInside==TRUE)
bReady = FALSE;

:commissar:

Seth Turtle
May 6, 2007

by Tiny Fistpump

West4th posted:

if(isBagInside==FALSE)
bReady =TRUE ;
else if(isBagInside==TRUE)
bReady = FALSE;

:commissar:

Using an else-if in this situation is wise. You don't want to match FALSE and TRUE simultaneously. And you've gotta save that ending 'else' for the third option that's sure to come up later on in development.

Supervillin
Feb 6, 2005

Pillbug

West4th posted:

if(isBagInside==FALSE)
bReady =TRUE ;
else if(isBagInside==TRUE)
bReady = FALSE;

:commissar:

I've seen a lot of this with ternary operators. Hypothetical: isValid = (checkForInvalid()) ? false : true. Usually in that order, so the "true" result actually returns false and vice versa.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

Seth Turtle posted:

Using an else-if in this situation is wise. You don't want to match FALSE and TRUE simultaneously. And you've gotta save that ending 'else' for the third option that's sure to come up later on in development.

It's been future proofed for quantum computing.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Supervillin posted:

I've seen a lot of this with ternary operators. Hypothetical: isValid = (checkForInvalid()) ? false : true. Usually in that order, so the "true" result actually returns false and vice versa.
!(There's not an operator that does this).

gibbed
Apr 10, 2006

Mustach posted:

!(There's not an operator that does this).
isValid = !checkForInvalid() ? true : false

:smug:

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

gibbed posted:

isValid = !checkForInvalid() ? true : false

:smug:

if (checkForInvalid().ToString().Length()==5) isValid=true;

zombienietzsche
Dec 9, 2003

Ensign Expendable posted:

if (checkForInvalid().ToString().Length()==5) isValid=true;

inline conditionals reduce readability and make it more difficult to add other options in the future. it should be

code:
if (checkForInvalid().ToString().Length() == 5)
{
    isValid = true;
}
else
{
    isValid = false;
}

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
*trips over himself trying to come up with an even better coding horror, spills all of his golden manbabies* Noooooooooooo..... :cry:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I believe we should be exploiting jump tables in a switch statement for maximum fastness :pseudo:

code:
switch (checkForInvalid().ToString().Length()) {
   case 5:
      isValid = true;
      break;
   case 4:
      isValid = false;
      break;
   default:
      throw new NonTrueOrFalseBooleanValueException();
}

Incoherence
May 22, 2004

POYO AND TEAR

Seth Turtle posted:

Using an else-if in this situation is wise. You don't want to match FALSE and TRUE simultaneously. And you've gotta save that ending 'else' for the third option that's sure to come up later on in development.
Clearly the third option is FileNotFound.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Incoherence posted:

Clearly the third option is FileNotFound.

I'm surprised it took this many posts to reach that.

Tikki
Aug 13, 2007
Life is too short for... No. Life is just too short!
code:
class String
  #Return the string in the right length, or truncated and appended with '...'
  def dotdotdotalize(max_length)
    return self.length <= max_length ? self : "#{self.first(max_length-3)}..."
  end
end
Looks like someone couldn't find truncate

Zombywuf
Mar 29, 2008

niteice posted:

I'm surprised it took this many posts to reach that.

I heard another set of values to booleans last night: True and Techcrunch

poopgiggle
Feb 7, 2006

it isn't easy being a cross dominate shooter.


An intern over the summer, trying to convert decimal into hex (I think, I don't really recall, but it was some inter-base conversion) in python:
code:
if str == 0:
   return "0"
elif str == 1:
   return "1"
...
elif str == 10:
   return "A"
...

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

Tikki posted:

code:
class String
  #Return the string in the right length, or truncated and appended with '...'
  def dotdotdotalize(max_length)
    return self.length <= max_length ? self : "#{self.first(max_length-3)}..."
  end
end
Looks like someone couldn't find truncate

Dotdotdotalize is a hilarious word though.

RussianManiac
Dec 27, 2005

by Ozmaugh

poopgiggle posted:

An intern over the summer, trying to convert decimal into hex (I think, I don't really recall, but it was some inter-base conversion) in python:
code:
if str == 0:
   return "0"
elif str == 1:
   return "1"
...
elif str == 10:
   return "A"
...

So is he getting a letter of recommendation?

poopgiggle
Feb 7, 2006

it isn't easy being a cross dominate shooter.


RussianManiac posted:

So is he getting a letter of recommendation?

He actually turned out to be pretty good at other stuff (he's double-majoring EE/CS and his EE skills are good) so probably. I wouldn't want him writing code though.

geetee
Feb 2, 2004

>;[
Just got an email from my coworker about the new intern arguing with the senior developer:

quote:

INTERN is arguing with S.DEVELOPER right now..

he doesn't want to learn php

and wants to do the webservice in C++

and wants to write a http handling library to do it

which is fine because:
"Maybe I haven't been coding long enough, but I've never written a line of
code that had a security vulnerability"

hm
I'm so glad I start my new job in a few weeks and only have one week left here.

Oh! The kicker... I was doing some internet detectiving on the intern's personal web site and there are plenty of XSS openings.

Space Kablooey
May 6, 2009


Go ahead and hack it and report back, but don't let him know that was you.
And send the hacked page to his senior developer. :haw:

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
Not coding, but this craigslist ad came up in reddit and will probably disappear so I'll just paste it:

Craigslist posted:

We are looking for candidates with at least 2 years of experience to join our start up software company. We are looknig for developers to come on board part time ($10/hour) but there is a huge opportunity for advancement.

Candidates must posses a bcahelor's degree. Candidates must also have full working knowledge of Php, Ruby on Rails, Java.
Note this job is for Manhattan, where the cost of living is, well, about $10 an hour.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
JOrbisPlayer:
code:
public void actionPerformed(ActionEvent e){
    if(e.getSource()==stats_button){
      String item=(String)(cb.getSelectedItem()); // cb is a combobox
/* ... */
      byte[] foo=item.getBytes();
      for(int i=foo.length-1; i>=0; i--){
        if(foo[i]=='/'){
          item=item.substring(0, i+1)+"stats.xml";
          break;
        }
      }
Okay, this was done in the year 2000, and it is supposed to work as an applet, so I thought that maybe it was done targeting Java 1.1, and maybe Java 1.1 didn't have String.lastIndexOf(). But as far as I can tell, lastIndexOf has always been a member of String.

And I just realized that it's not an Applet, but a JApplet, so it's at minimum Java 1.2, which definitely has lastIndexOf().

GROVER CURES HOUSE
Aug 26, 2007

Go on...
So while messing around in an old codebase I stumbled on this:
code:
#define HEREBEDRAGONS //do not comment out!!! crashes gcc
I could not find a single reference to the flag. GCC did, in fact, crash if you commented it out. How does that even work? :psyduck:

TheSleeper
Feb 20, 2003
Clearly GCC needs a warning about the upcoming dragons so it can put on its suit of armor. If you comment it out, GCC ignores it and the dragon gets it, causing it to crash.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Seriously, I'm pretty sure the Dragon text devoted an entire chapter to fending off mythical beasts or something :confused:

Opinion Haver
Apr 9, 2007

Broken Knees Club posted:

So while messing around in an old codebase I stumbled on this:
code:
#define HEREBEDRAGONS //do not comment out!!! crashes gcc
I could not find a single reference to the flag. GCC did, in fact, crash if you commented it out. How does that even work? :psyduck:

I... you have to figure out what the hell is going on here.

mr_jim
Oct 30, 2006

OUT OF THE DARK

I am adding that to every program I write, just in case.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Or grep for it after running gcc -E and see if it's getting inserted into an unexpected place.

BattleMaster
Aug 14, 2000

Is it really a crash or is it just a compile error?

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
I'd love it if you could track down what that bug was, because weird compiler bugs have always fascinated me.

A few years ago I was the TA for one of our C++ courses, and when it came time to grade students' projects, I would compile and run their code and occasionally it would crash with "SIGILL: illegal instruction". Thinking they were doing something like blowing the stack, I pulled up gdb but it was actually g++ generating an incorrect CALL instruction. Instead of the correct destination address, it was basically generating "CALL (address of this instruction + 1)", which of course would never be correct.

Sadly I was never able to figure out how to duplicate it reliably. Sometimes forcing -O0 would fix it, but then on another student's code it would be broken under -O0 but -O3 would work instead.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

Broken Knees Club posted:

So while messing around in an old codebase I stumbled on this:
code:
#define HEREBEDRAGONS //do not comment out!!! crashes gcc
I could not find a single reference to the flag. GCC did, in fact, crash if you commented it out. How does that even work? :psyduck:

I things like that Magic/More Magic switch in all manifestations. If you have nothing better to do, tinkering with them is an excellent way to waste time.

Incoherence
May 22, 2004

POYO AND TEAR

Flobbster posted:

I'd love it if you could track down what that bug was, because weird compiler bugs have always fascinated me.

A few years ago I was the TA for one of our C++ courses, and when it came time to grade students' projects, I would compile and run their code and occasionally it would crash with "SIGILL: illegal instruction". Thinking they were doing something like blowing the stack, I pulled up gdb but it was actually g++ generating an incorrect CALL instruction. Instead of the correct destination address, it was basically generating "CALL (address of this instruction + 1)", which of course would never be correct.

Sadly I was never able to figure out how to duplicate it reliably. Sometimes forcing -O0 would fix it, but then on another student's code it would be broken under -O0 but -O3 would work instead.
The only time I've ever seen a SIGILL was a situation where I managed to compile something whose dependencies included two classes with the same name, and somehow the linker got sufficiently confused that rather than, I don't know, complaining that there were two classes with the same name, or combining them sensibly, it decided to merge the two together into a single vtable that was missing several methods from each, so that when I called one of the missing methods the program of course crashed.

I would love for someone to explain to me (slowly) just why that happened and why the person who finally figured this out gave me the impression that this behavior wasn't a bug.

Presto
Nov 22, 2002

Keep calm and Harry on.

Flobbster posted:

Sadly I was never able to figure out how to duplicate it reliably. Sometimes forcing -O0 would fix it, but then on another student's code it would be broken under -O0 but -O3 would work instead.
gcc is just bizarre like that. I was working with code similar to this:
code:
somevar = someval;
if (somevar != prev_somevar) {
    do_something();
    prev_somevar = somevar;
}
With -O2 gcc apparently decided the 'if' block was not needed and optimized it away, so the code failed; but with no optimization, it worked perfectly. If I stuck a printf before the 'if', then it would work with -O2.

I ended up having to declare somevar volatile to fool the optimizer.

poopgiggle
Feb 7, 2006

it isn't easy being a cross dominate shooter.


^^^ Regarding workarounds for bad compiler optimization...

One of our CS professors was trying to write a delay into some code back in the day (apparently before the sleep call) and did something like this:

code:
dummyvar = 0
for(i=0;i<1000000;i++){
dummyvar++;
}
However, the compiler figured out that dummyvar wasn't being used anywhere else, and so the loop wasn't doing anything, so it just cut it out. This was the solution:

code:
dummyvar = 0
for(i=0;i<1000000;i++){
dummyvar++;
goto label;
label:
}
(This may not actually be how goto is used in C)

The compiler took one look at the goto statement and was like, "gently caress it, I'm out." I don't recommend ever actually doing this but it's funny that it happened (and that it was perpetrated by one of the most brilliant people I've ever met).

EDIT: Took out a really retarded infinite loop. Don't post while sleep-deprived, kids!

poopgiggle fucked around with this message at 15:28 on Oct 20, 2009

Zombywuf
Mar 29, 2008

Presto posted:

gcc is just bizarre like that. I was working with code similar to this:
code:
somevar = someval;
if (somevar != prev_somevar) {
    do_something();
    prev_somevar = somevar;
}
With -O2 gcc apparently decided the 'if' block was not needed and optimized it away, so the code failed; but with no optimization, it worked perfectly. If I stuck a printf before the 'if', then it would work with -O2.

I ended up having to declare somevar volatile to fool the optimizer.

If somevar was being modified in a separate thread it is correct to optimize that way. However I suspect what was happening was the optimizer was modifying prev_somevar (or the register it had it in) early and then another part of the optimizer was seeing it as if you'd written:
code:
prev_somevar = somevar;
if (somevar != prev_somevar) {
  ...

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Incoherence posted:

The only time I've ever seen a SIGILL was a situation where I managed to compile something whose dependencies included two classes with the same name, and somehow the linker got sufficiently confused that rather than, I don't know, complaining that there were two classes with the same name, or combining them sensibly, it decided to merge the two together into a single vtable that was missing several methods from each, so that when I called one of the missing methods the program of course crashed.

I would love for someone to explain to me (slowly) just why that happened and why the person who finally figured this out gave me the impression that this behavior wasn't a bug.

It's pretty easy to reproduce this with objects with C linkage (e.g. everything in C):

code:
a.c:
  int val = 0;

b.c:
  int val();
  int main() {
    if (val()) return 1;
  }
If you understand why this compiles and links, and why it doesn't link if you compile the files in C++ instead, you'll be a long way towards understanding what went wrong with your case.

Adbot
ADBOT LOVES YOU

ZorbaTHut
May 5, 2005

wake me when the world is saved

Flobbster posted:

I'd love it if you could track down what that bug was, because weird compiler bugs have always fascinated me.

I used to work for a game company that was making software for the PS2. At one point I went and rigged up a new super-fast renderer for our automap, all written up in VU0 assembly code so it would run on what was essentially the PS2's vertex processor. Got it blazing fast and debugged, checked it in, forgot about it.

About a week later someone made a build and got it to crash. I looked at it, couldn't figure out what was going on. Added some debug to it, rebuilt, and it worked. Removed debug, rebuilt, and it worked. Okay . . . cosmic ray? Buffer overflow? Well, it's working now, we'll just ignore it.

A few days after that it melts again. I rebuild it. It works. I am worried, and go to ask my boss about it.

He figures out the problem.

The assembler for the PS2 was an optimizing assembler. It took my carefully-written assembly and munged it around to work better. Normally I'm okay with this. However, it didn't have a "optimization setting" or anything so mundane as that. No, it had a timeout. A realtime timeout. You'd say "optimize it for 5 seconds!" and boy howdy it would optimize that sucker for exactly 5 realtime seconds. Regardless of how much CPU it was actually getting during that time. And to make things worse, it was buggy. So, depending on how much CPU it got . . . well, it might just spit out invalid assembly once in a while.

We told it to optimize for 24 hours, and discovered that it would actually reach a point where it considered itself "finished". That was the fix: put that in, and hope it didn't break for some other reason. Which, to the best of my knowledge, it never did.

God the PS2 dev tools were crappy. I thought of one story, started writing that sentence, and before I'd finished I'd thought of two more. :(

(incidentally I totally forgot I'd posted in this thread, but if anyone still wants answers to questions posed way back over here I can answer 'em)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply