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
TSDK
Nov 24, 2003

I got a wooden uploading this one

Mill Town posted:

Data structure hell, just stuff all the strings into a hash set.

Near-constant lookup time, it'll actually perform better than an if-else block.
1) There is no standard library hash set in C++ (and this is an embedded system, so boost is not an option without butchering up a custom version).
2) They're stricmps, not strcmps, so you'd still need to do some faffing to get the hashing (or sorting if you want to use a std::map) working properly.

It's only done once per load, so it's not in a performance critical section, but it is annoying that it'll take longer than it should for want of a few extra keywords. It's sloppy rather than outright terrible.

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Just so you know your compiler probably has <tr1/unordered_set> (not that it's necessary here)

1337JiveTurkey
Feb 17, 2005

Ryouga Inverse posted:

the real wtf is that it actually saves to the file (without asking) and then asks if you want to save the file, but really it's asking "do you not want to delete the file?"

I do something similar when I'm supposed to write out an error log with an execution trace only if some error occurs. At the end, if it succeeded with no errors, I delete it. It's perfect because if it fails to delete for some reason or another, then I needed the log file because that's an error. :v:

twodot
Aug 7, 2005

You are objectively correct that this person is dumb and has said dumb things

TSDK posted:

1) There is no standard library hash set in C++ (and this is an embedded system, so boost is not an option without butchering up a custom version).
2) They're stricmps, not strcmps, so you'd still need to do some faffing to get the hashing (or sorting if you want to use a std::map) working properly.

It's only done once per load, so it's not in a performance critical section, but it is annoying that it'll take longer than it should for want of a few extra keywords. It's sloppy rather than outright terrible.
3) Even if you had a set, knowing that p_string is some item in that set, doesn't help you know which stuff you need to execute, unless your set is actually a map from strings to function pointers, which I think would be worse than what you have now.

zergstain
Dec 15, 2005

Avenging Dentist posted:

Look upon your works, ye coder, and despair!

The guy sitting next to me at work indents almost that badly, and he can't seem to decide between tabs or spaces.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Found this the other day at work and thought it would liven things up a bit in here.
php:
<?
/**
     * Loads the last group code assigned to each active high group.
     * This list should be updated periodically
     */
    private function LoadHighGroups()
    {
        $this->aryHighGroups = array(
            "001" => "06",
            "002" => "06",
            "003" => "04",
            "004" => "08",
            "005" => "08",
            "006" => "08",
            "007" => "08",
            "008" => "92",
            "009" => "90",
            "010" => "90",
            "011" => "90",
            "012" => "90",
            "013" => "90",
// 800 MORE LINES OF THIS
?>
I guess I have some updating deleting to do.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



php:
<?
if(strpos($userid,".")>=0)$userid=-5;
?>
Lead Programmer: Hey, how come all the userids in this table are -5?

Me, 1 hour later: gently caress!

Now I'm searching our entire codebase for more cases of PHP programmers not understanding PHP.

Obligatory: PHP is a coding horror :(

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
What the hell was that code even supposed to do?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Sartak posted:

What the hell was that code even supposed to do?

Possibly $userid -= 5?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Even still, why would you subtract 5 from the userid if it contains a period?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Sartak posted:

Even still, why would you subtract 5 from the userid if it contains a period?

I've seen worse things. Hell, I've written worse things (though I usually at least have the awareness to apologize for it in comments).

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Avenging Dentist posted:

I've seen worse things. Hell, I've written worse things (though I usually at least have the awareness to apologize for it in comments).

code:
C    S X=X1 Q:'X  D H S %H=%H+X2 D YMD S:$P(X1,".",2) X=X_"."_$P(X1,".",2) K X1,X2 Q
S    S %=%#60/100+(%#3600\60)/100+(%\3600)/100 Q
     ;
:laugh:

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Sartak posted:

Even still, why would you subtract 5 from the userid if it contains a period?

The userid is supposed to be coming from a 3rd party authentication system and apparently there were periods getting in there somehow (and probably causing database errors) from someone at some point in the last 5 years. Rather than force people writing code upstream of the core authentication system to deal with it properly, someone decided it would be a great idea to hide a line in the system that will gently caress the userid right in the ear in this one specific case and then went and did it in a profoundly stupid way. I could post a bunch of our codebase in this thread but I'm extra pissed about this one because I read over this line 4 or 5 times before it occurred to me why it was wrong.

It's supposed to set the userid to -5, by the way (it's = -5 not -= 5).

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

shrughes posted:

Codepadded into #cobol:

code:
  for (int b=a; a>0; a--)
  {
    cout << a << "\n";
    myfile << a << "\n";

  } while (a > 0);

I don't get it, what exactly am I looking at? Is it a for loop or a while loop?

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.
It's just a for-loop followed by a while-loop. It's hosed-up in other ways, but it's not a special syntax or anything like that.

Fehler
Dec 14, 2004

.

Triple Tech posted:

I don't get it, what exactly am I looking at? Is it a for loop or a while loop?
As far as I can see this code is the same as:
code:
  for (int b=a; a>0; a--)
  {
    cout << a << "\n";
    myfile << a << "\n";

  }

while (a > 0) {};
And since a == 0 after the for-loop nothing happens with the while loop.

terminatusx
Jan 27, 2009

:megaman:Indie Game Dev and Bringer of the Apocalypse
code:
<?

/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -----------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2006 BoonEx Group
*     website              : [url]http://www.boonex.com/[/url]
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License. 
* [url]http://creativecommons.org/licenses/by/3.0/[/url]
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Creative Commons Attribution 3.0 License for more details. 
* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin, 
* see license.txt file; if not, write to [email]marketing@boonex.com[/email]
***************************************************************************/

	$sTemplName = 'TEST';
?>
a very useful file, worthy of modularization, to be sure. if anyone has worked with Dolphin you know how frustrating it is to find anything in the code, which ping-pongs between countless files.

functional
Feb 12, 2008

terminatusx posted:

a very useful file, worthy of modularization, to be sure.

Do not question the cult of modularization

epswing
Nov 4, 2003

Soiled Meat
Explanation of what this is in a moment...

Edit: So, here we have a "transformer". We get journal articles from publishers in all sorts of formats, mostly xml. Those that are in xml we transform to match our format. In java. Using org.w3c.dom.*.

Each transformer, of which there are about 50, does something slightly differently than the next, and generally features a ~700 line processXML method, most of which is in a try/catch block. The catch block is, unsurprisingly, catch(Exception e).

:v: "Ok epswing, we're going to have you edit one of the transformers because a publisher has changed their format."

:cool: "Ok sure..."

:v: http://paste.ifies.org/300

:( "Jesus. Christ."

epswing fucked around with this message at 23:18 on Jan 29, 2009

mr_jim
Oct 30, 2006

OUT OF THE DARK

From http://www.jgc.org/blog/2009/01/single-line-assignment-filled-with-epic.html:

code:
dir.permissions = 666; // Make the file writable
There are so many kinds of bad right there.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

mr_jim posted:

There are so many kinds of bad right there.

Yeah, especially the blog's title. :pwn:

terminatusx
Jan 27, 2009

:megaman:Indie Game Dev and Bringer of the Apocalypse

mr_jim posted:

code:
dir.permissions = 666; // Make the file writable
There are so many kinds of bad right there.

Little known fact, setting a file's permissions to 666 gives read and write access to everyone, and allows Satan to execute YOU. in hell.
...with a trident.

mr_jim
Oct 30, 2006

OUT OF THE DARK

terminatusx posted:

Little known fact, setting a file's permissions to 666 gives read and write access to everyone, and allows Satan to execute YOU. in hell.
...with a trident.

Actually, I think the Satan thing comes up when you set a directory's permissions to 666 decimal instead of 0666 octal. With no user intervention. And then put in a misleading comment.

terminatusx
Jan 27, 2009

:megaman:Indie Game Dev and Bringer of the Apocalypse
whoops, my mistake.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
I haven't found the horror itself yet, but it's leaving markings everywhere:

code:
internal void ScalarCallback(IntPtr context, int nArgs, IntPtr argsptr)
{
    System.Console.WriteLine ("about to convert params, nArgs = {0}", nArgs);
    object[] parms = ConvertParams(nArgs, argsptr);
    System.Console.WriteLine ("About to call {0}:Invoke([\"{1}\"])", _debug_name, parms[0]);
    object retval = Invoke(parms);
    System.Console.WriteLine ("got retval: {0}", retval == null?  "null" : retval.ToString());
    SetReturnValue(context, retval);
    System.Console.WriteLine ("set return value");
}

public object Invoke (object[] args)
{
    System.Console.WriteLine ("args.Length = {0}", args.Length);
    System.Console.Out.Flush ();
    System.Console.WriteLine ("args[0].GetType() = {0}", args[0].GetType());
    System.Console.Out.Flush ();
    System.Console.WriteLine ("args[0] = {0}", args[0]);
    System.Console.Out.Flush ();
    return args[0];
}
code:
about to convert params, nArgs = 1
About to call TEST_NOCASE:Invoke(["test"])
args.Length = 1
args[0].GetType() = System.String
args[0] = test
got retval: test
set return value

about to convert params, nArgs = 1
About to call :Invoke(["test"])
got retval: System.Xml.XmlAttribute
set return value
:iiam:

Strong Sauce
Jul 2, 2003

You know I am not really your father.





No Safe Word posted:

For one of our clients (in the healthcare business) they literally had at least five (and I think it may actually have been seven) options in the gender field. I forget them all, but it was at least: Male, Female, Unspecified and I think there was a "Neither" or "Both" in there somewhere.

Obviously your healthcare has a few aliens under it's insurance policy :colbert:

Fenderbender
Oct 10, 2003

You have the right to remain silent.
Fenderbender Presents: Line 1208

$error = QuerySubs::insert_vital_record($GLOBAL_DATA_DB, $GLOBAL_DATA_HOST, $GLOBAL_DATA_ACCOUNT, $GLOBAL_DATA_PASS, [$mrn, $var{uniq}, $var{capture_date}, $var{capture_time}, $var{vitals_units}, $var{vitals_height_1}, $var{vitals_height_2}, $var{vitals_weight_1}, $var{vitals_weight_2}, $var{vitals_temperature}, $var{vitals_temperature_method}, $var{vitals_respiration}, $var{vitals_head_circ}, $var{vitals_waist_circ}, $var{vitals_bmi}, $var{vitals_bsa}, $var{vitals_lmp}, $var{bpp_sitting_systolic}, $var{bpp_sitting_diastolic}, $var{bpp_sitting_extremity}, $var{bpp_sitting_pulse}, $var{bpp_sitting_rhythm}, $var{bpp_standing_systolic}, $var{bpp_standing_diastolic}, $var{bpp_standing_extremity}, $var{bpp_standing_pulse}, $var{bpp_standing_rhythm}, $var{bpp_supine_systolic}, $var{bpp_supine_diastolic}, $var{bpp_supine_extremity}, $var{bpp_supine_pulse}, $var{bpp_supine_rhythm}, $var{pain_assessment_under_8}, $var{pain_assessment}, $var{pain_assessment_comments}, $var{pulse_oximetry_heart_rate}, $var{pulse_oximetry_o2_saturation}, $var{pulse_oximetry_delivery_method}, $var{pulse_oximetry_extremity}, $var{pulse_oximetry_fio2}, $var{pulse_oximetry_flow}, $e3::user, $var{clinic_intake_tobacco_usage}, $var{clinic_intake_tobacco_date}, $var{clinic_intake_tobacco_current_packs_per_day}, $var{clinic_intake_allergies}, $var{clinic_intake_allergies_comments}, $var{clinic_intake_medication_list_reviewed_with_patient}, $var{clinic_intake_prescription_needed}, $var{clinic_intake_prescription_needed_comments}, $var{clinic_intake_chief_complaint},$var{visit_details}, $var{capture_date}, $var{capture_time}, $var{vitals_units}, $var{vitals_height_1}, $var{vitals_height_2}, $var{vitals_weight_1}, $var{vitals_weight_2}, $var{vitals_temperature}, $var{vitals_temperature_method}, $var{vitals_respiration}, $var{vitals_head_circ}, $var{vitals_waist_circ}, $var{vitals_bmi}, $var{vitals_bsa}, $var{vitals_lmp}, $var{bpp_sitting_systolic}, $var{bpp_sitting_diastolic}, $var{bpp_sitting_extremity}, $var{bpp_sitting_pulse}, $var{bpp_sitting_rhythm}, $var{bpp_standing_systolic}, $var{bpp_standing_diastolic}, $var{bpp_standing_extremity}, $var{bpp_standing_pulse}, $var{bpp_standing_rhythm}, $var{bpp_supine_systolic}, $var{bpp_supine_diastolic}, $var{bpp_supine_extremity}, $var{bpp_supine_pulse}, $var{bpp_supine_rhythm}, $var{pain_assessment_under_8}, $var{pain_assessment}, $var{pain_assessment_comments}, $var{pulse_oximetry_heart_rate}, $var{pulse_oximetry_o2_saturation}, $var{pulse_oximetry_delivery_method}, $var{pulse_oximetry_extremity}, $var{pulse_oximetry_fio2}, $var{pulse_oximetry_flow}, $e3::user, $var{clinic_intake_tobacco_usage}, $var{clinic_intake_tobacco_date}, $var{clinic_intake_tobacco_current_packs_per_day}, $var{clinic_intake_allergies}, $var{clinic_intake_allergies_comments}, $var{clinic_intake_medication_list_reviewed_with_patient}, $var{clinic_intake_prescription_needed}, $var{clinic_intake_prescription_needed_comments}, $var{clinic_intake_chief_complaint}, $var{visit_details}]);

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



More!
php:
<?
   $today = getdate();
   $todayDate = sprintf("%04d%02d%02d_%02d%02d%02d", $today['year'], 
      $today['mon'], $today['mday'], $today['hours'], 
      $today['minutes'], $today['seconds']);
   $todayDate = $todayDate ^ "pippopippopippo";
   $toret = $userid . "." . $todayDate;
?>
Thank loving god it was commented out, but my brain shut down for a second when I saw $todayDate = $todayDate ^ "pippopippopippo"; in the grep results.

Mill Town
Apr 17, 2006

Munkeymon posted:

More!
php:
<?
   $today = getdate();
   $todayDate = sprintf("%04d%02d%02d_%02d%02d%02d", $today['year'], 
      $today['mon'], $today['mday'], $today['hours'], 
      $today['minutes'], $today['seconds']);
   $todayDate = $todayDate ^ "pippopippopippo";
   $toret = $userid . "." . $todayDate;
?>
Thank loving god it was commented out, but my brain shut down for a second when I saw $todayDate = $todayDate ^ "pippopippopippo"; in the grep results.

Apparently XOR is defined on strings in PHP. :psyduck:
http://ca.php.net/manual/en/language.operators.bitwise.php

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Mill Town posted:

Apparently XOR is defined on strings in PHP. :psyduck:
http://ca.php.net/manual/en/language.operators.bitwise.php

HAHAHahah haha hah ha :suicide:

Even better: the manual says the only operators that work on strings are . and .= http://us.php.net/manual/en/language.operators.string.php

mr_jim
Oct 30, 2006

OUT OF THE DARK

Mill Town posted:

Apparently XOR is defined on strings in PHP. :psyduck:
http://ca.php.net/manual/en/language.operators.bitwise.php

:wtc:

How is that supposed to be useful?

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

mr_jim posted:

:wtc:

How is that supposed to be useful?

XOR encoding leaps to mind...
code:
php -r 'echo "Plaintext\n"^"gobbledygook";'
7
 e
php -r 'echo "Plaintext\n"^"gobbledygook"^"gobbledygook";'
Plaintext
Beyond that, no idea.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Otto Skorzeny posted:

Just so you know your compiler probably has <tr1/unordered_set> (not that it's necessary here)

As of gcc 4.3 unordered_set and friends are in the main include folder and under namespace std :themoreyouknow:

shrughes
Oct 11, 2008

(call/cc call/cc)

mr_jim posted:

:wtc:

How is that supposed to be useful?

Why, so you can encrypt passwords with xor encryption!

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.
Another feather in PHP's security hat

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge
One time pads are bad how :confused:

edit: Whoops, missed the "encrypt passwords" bit

Zakalwe fucked around with this message at 03:52 on Feb 5, 2009

mr_jim
Oct 30, 2006

OUT OF THE DARK

shrughes posted:

Why, so you can encrypt passwords with xor encryption!

Encryption occurred to me after posting; I've been reading up on stream ciphers lately. I guess the context it was being used in threw me off.

code:
$todayDate = $todayDate ^ "pippopippopippo";
I have no idea what this is supposed to achieve.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

mr_jim posted:

Encryption occurred to me after posting; I've been reading up on stream ciphers lately. I guess the context it was being used in threw me off.

code:
$todayDate = $todayDate ^ "pippopippopippo";
I have no idea what this is supposed to achieve.

Seems to me all of that above could be written as:
php:
<?
$toret=$userid.'.'.(date('Ymd_His')^'pippopippopippo');
?>
which seems to be making some sort of maybe session key?

Mill Town
Apr 17, 2006

mr_jim posted:

Encryption occurred to me after posting; I've been reading up on stream ciphers lately. I guess the context it was being used in threw me off.

code:
$todayDate = $todayDate ^ "pippopippopippo";
I have no idea what this is supposed to achieve.

I wasn't sure either, so I stuffed it in a file and ran it (with $userid="test"):
$ php test.php
test.BY@I_BYE/_EYFD^

It does... something.

Adbot
ADBOT LOVES YOU

mr_jim
Oct 30, 2006

OUT OF THE DARK

I'm pretty sure FeloniousDrunk is right about it generating session keys. That didn't occur to me because a) I'm not a web programmer, and b) "pippopippopippo" is odd enough that I thought it must have some significance beyond obfuscating the time stamp. :downs: I'm retarded.

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