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
spiritual bypass
Feb 19, 2008

Grimey Drawer

Avenging Dentist posted:

Guys, the a[i] / i[a] equivalence is just because the standard defines a[i] as being equivalent to *(a+i).

:waycool: Thanks for clearing that up.

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

royallthefourth posted:

:waycool: Thanks for clearing that up.

Are you trying to be sarcastic or something?

Because if you are, this thread is about to get way more interesting.

Dijkstracula
Mar 18, 2003

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

Avenging Dentist posted:

Guys, the a[i] / i[a] equivalence is just because the standard defines a[i] as being equivalent to *(a+i).
The thing is, though, this makes sense until you think about it for a bit and realize that it's not *(a+i), it's *(a + (i * sizeof(thetype))), so it's not commutative in that way unless the size of the type happens to be the size of the architecture's word.

Was this not the case back in the good old days? Were all data types 16 bits on the PDP-11 or something?

Avenging Dentist
Oct 1, 2005

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

Dijkstracula posted:

The thing is, though, this makes sense until you think about it for a bit and realize that it's not *(a+i), it's *(a + (i * sizeof(thetype))), so it's not commutative in that way unless the size of the type happens to be the size of the architecture's word.

You may want to read up on your pointer arithmetic.

Also the reason *(a+i) isn't commutative given that one of {a, i} is a pointer and one an integral type is because a+i isn't a binary operator in that case. Binary operators are defined as a function f: S × S → S, and a and i are not members of the same set. Indeed, if we let S be the set of pointer types*, the binary operator + is invalid.

* Including arrays, which degrade into pointers.

Avenging Dentist fucked around with this message at 06:16 on Sep 19, 2009

Dijkstracula
Mar 18, 2003

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

Avenging Dentist posted:

You may want to read up on your pointer arithmetic.

edit: ah, talked to #cobol - the compiler implicitly adds the stride based on sizeof(thetype). I got it now. :)


sizeof(float) = 4
(a + 0) = 0x7fff5fbff850
(a + 1) = 0x7fff5fbff854
(a + 2) = 0x7fff5fbff858
(a + 3) = 0x7fff5fbff85c
(a + 4) = 0x7fff5fbff860
sizeof(void) = 1
(b + 0) = 0x7fff5fbff850
(b + 1) = 0x7fff5fbff851
(b + 2) = 0x7fff5fbff852
(b + 3) = 0x7fff5fbff853
(b + 4) = 0x7fff5fbff854

Dijkstracula fucked around with this message at 08:15 on Sep 19, 2009

ColdPie
Jun 9, 2006

Avenging Dentist posted:

You may want to read up on your pointer arithmetic.

Also the reason *(a+i) isn't commutative given that one of {a, i} is a pointer and one an integral type is because a+i isn't a binary operator in that case. Binary operators are defined as a function f: S × S → S, and a and i are not members of the same set. Indeed, if we let S be the set of pointer types*, the binary operator + is invalid.

* Including arrays, which degrade into pointers.

Holy poo poo, AD explained his troll post without having to be explicitly asked to do so. Admittedly, he had to edit it in 10 minutes later, but he still did it. Time to start looking for other signs of the apocalypse.

It is a joke, please refrain from projecting your personal sexual preferences.

Zombywuf
Mar 29, 2008

ColdPie posted:

Holy poo poo, AD explained his troll post without having to be explicitly asked to do so. Admittedly, he had to edit it in 10 minutes later, but he still did it. Time to start looking for other signs of the apocalypse.

It is a joke, please refrain from projecting your personal sexual preferences.
The other day I saw it raining baked beans and naked women.

Avenging Dentist
Oct 1, 2005

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

ColdPie posted:

Holy poo poo, AD explained his troll post without having to be explicitly asked to do so. Admittedly, he had to edit it in 10 minutes later, but he still did it. Time to start looking for other signs of the apocalypse.

If you thought the second paragraph explained the first paragraph, I have very bad news for you about your brain (it's broken).

Zombywuf
Mar 29, 2008

Avenging Dentist posted:

If you thought the second paragraph explained the first paragraph, I have very bad news for you about your brain (it's broken).
It is demonstably false, as can be seen from making the set S the union of the set of integers and pointers. Given that in classical logic (which I assume we are operating in) if you can prove a false statement you can prove anything, the latter paragraph clearly does prove, and thereby explain, the former.

shrughes
Oct 11, 2008

(call/cc call/cc)

Zombywuf posted:

It is demonstably false, as can be seen from making the set S the union of the set of integers and pointers. Given that in classical logic (which I assume we are operating in) if you can prove a false statement you can prove anything, the latter paragraph clearly does prove, and thereby explain, the former.

Huh? If S is the union of Z and P, then for + to be a binary operator, you'd have to be able to add two pointers together.

However, we could say that + : (Z x P) U (P x Z) -> P

And thus the pointer arithmetic + operator is a commutative operator function is commutative.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Zombywuf posted:

It is demonstably false, as can be seen from making the set S the union of the set of integers and pointers.

But if we take S as the union set, then we have to admit + as a partial function, as (pointer + pointer) is a nonsense operation.

Zombywuf
Mar 29, 2008

shrughes posted:

Huh? If S is the union of Z and P, then for + to be a binary operator, you'd have to be able to add two pointers together.

However, we could say that + : (Z x P) U (P x Z) -> P

And thus the pointer arithmetic + operator is a commutative operator function is commutative.

Avenging Dentist posted:

Binary operators are defined as a function f: S × S → S, and a and i are not members of the same set.
Is the false statement. a and i are trivially members of the set S = {a, i}.

mr_jim
Oct 30, 2006

OUT OF THE DARK

ShoulderDaemon posted:

But if we take S as the union set, then we have to admit + as a partial function, as (pointer + pointer) is a nonsense operation.

With casting, anything is possible.

code:
    char *a = malloc(1);
    char *b = malloc(1);

    char *c = (char*)((long)a + (long)b);
Though I wouldn't try dereferencing the resulting pointer, so yes, it is a nonsense operation. And casting is probably cheating.

shrughes
Oct 11, 2008

(call/cc call/cc)

Zombywuf posted:

Is the false statement. a and i are trivially members of the set S = {a, i}.

Still no good; if + were a binary operator on {a, i} then (a + a) would have to make sense.

Zombywuf
Mar 29, 2008

shrughes posted:

Still no good; if + were a binary operator on {a, i} then (a + a) would have to make sense.
That's fine, just make it a.

shrughes
Oct 11, 2008

(call/cc call/cc)

Zombywuf posted:

That's fine, just make it a.

Even so, a+i would have to be in the set. This only works if i = 0.

Avenging Dentist
Oct 1, 2005

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

Zombywuf posted:

That's fine, just make it a.

I shudder to think of how you program C.

EDIT: Oh by the way, your understanding of classical logic w.r.t. proof is adorable.

Avenging Dentist fucked around with this message at 21:08 on Sep 20, 2009

Zombywuf
Mar 29, 2008

Avenging Dentist posted:

I shudder to think of how you program C.
I wasn't talking about C, I was talking about S.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Hey guys let's use the Zombywuf method of proof: Given "false", we find that Zombywuf is a bad logician since "false -> Zombywuf is a bad logician" is a true statement.

Zombywuf
Mar 29, 2008

Avenging Dentist posted:

Hey guys let's use the Zombywuf method of proof: Given "false", we find that Zombywuf is a bad logician since "false -> Zombywuf is a bad logician" is a true statement.
I think you'll find that in the Zombywuf system of logical deduction:

Sequent I totally didn't just make up posted:

false → Zombywuf is a bad logician ⊢ Avenging Dentist is a bad poster

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
cout << 0[your_good_posts];

Segmentation fault

king_kilr
May 25, 2007

Otto Skorzeny posted:

cout << 0[your_good_posts];

Segmentation fault

invalid types ‘int[int]’ for array subscript

Zombywuf
Mar 29, 2008

Otto Skorzeny posted:

cout << 0[your_good_posts];

Segmentation fault

You're saying I have < 0x7fffaf0dd3cc good posts???

floWenoL
Oct 23, 2002

Avenging Dentist posted:

I shudder to think of how you program C.

EDIT: Oh by the way, your understanding of classical logic w.r.t. proof is adorable.

Maybe Zombywuf studied classical logic at the same time he studied probability theory.

ton1c
Apr 30, 2005
So I used to administrate this PHP shoutcast script (I didn't do any real coding, just forums/billing and poo poo). The guy who did the coding was alright, I was pretty young at the time and so was he so we didn't have a great idea in what we were doing, and as such this code I'm about to paste was produced. The TL/DR is that the application was basically for starting/managing shoutcast servers. This particular function starts shoutcast servers using the shell_exec() PHP method, which you may know was patched in version 4, since you shouldn't start running programs using this.

Behold, this abomination:
code:
function start_serv($id)
{

	/*
		check if the shoutcast server is online
		If server is offline or undetectable then continue.

		NOTE: permissions are NOT checked here
			they must be checked before using
			the start_serv() function.
		
	*/

	global $setting;
	global $userdata;
	global $db_prefix;


	$serverdata = mysql_fetch_array(  mysql_query("SELECT * FROM ".$db_prefix."servers WHERE id='".$id."'")  );
	bandwidth($serverdata['id'], $serverdata["logfile"], "./logs/", true);


	$ini_query = mysql_query("SELECT * FROM ".$db_prefix."ini_sets WHERE type='1' AND conf_name!='none'");
	$ini_content = "";
	while($data = mysql_fetch_array($ini_query))
	{
		$data["field"] = ereg_replace("c_", "", $data["field"]);
		if ($serverdata[$data["field"]] != "" )
		{
			$ini_content .= $data["conf_name"]."=".unsecure($serverdata[$data["field"]])."\r\n";
		}
	}

	if ( strstr($setting['os'],'windows') )
	{
		$filename = $setting['dir_to_cpanel']."temp\\".$serverdata['portbase']."_".time().".ini";
	}else{
		$filename = BASE."temp/".$serverdata['portbase']."_".time().".conf";
	}

	$handle = fopen($filename, "a");
	if (fwrite($handle, $ini_content) === FALSE)
	{
		return false;
	}
	fclose($handle);

	if ( strstr($setting['os'],'windows') )
	{
		//this starts the server then checks for the latest pid
		$WshShell = new COM("WScript.Shell");
		$oExec = $WshShell->Run($setting['dir_to_cpanel']."files/".$setting['os']."/sc_serv.exe ".$filename, 3, false);
		$output = array();

		exec('tasklist /fi "Imagename eq  sc_serv.exe" /NH /FO CSV', $output);
		$count = count($output) - 1;	//Array starts at 0, so we minus 1 to get the real count

		// Find the PID
		$line = explode("," , $output[$count]);
		$pid = str_replace('"', '', $line['1']);
		$pid = trim($pid);

		// If the output contains info the server was not started successfully
		if (strstr($output[$count],"INFO:"))
		{
			return false;
		}

	}else{
		// This will return the pid straight from shell
		$pid = shell_exec("nohup ".$setting['dir_to_cpanel']."files/".$setting['os']."/sc_serv ".$filename." > /dev/null & echo $!");
		if (!isset($pid) || $pid == "")
		{
			return false;
		}
		$output = array();
		exec("ps -p $pid --no-headers", $output);
		if (count($output) == 0)
		{
			return false;
		}	
	}

	$select_pid = mysql_query("SELECT * FROM ".$db_prefix."servers WHERE pid='".$pid."'");
	if (!$pid || $pid == "" || mysql_num_rows($select_pid) >= 1)
	{
		return false;
	}

	mysql_query("UPDATE ".$db_prefix."servers SET pid='$pid' WHERE id='$id'");
	return $pid;
}
Edit: I have a whole loving application of this poo poo.

ton1c fucked around with this message at 19:55 on Sep 21, 2009

geetee
Feb 2, 2004

>;[
What's wrong with shell_exec?

RussianManiac
Dec 27, 2005

by Ozmaugh
probably because it is a huge security flaw, unless all variables passed to exec and sql queries are thoroughly sanitized.

geetee
Feb 2, 2004

>;[

RussianManiac posted:

probably because it is a huge security flaw, unless all variables passed to exec and sql queries are thoroughly sanitized.

It's not a flaw. It's a potential vulnerability if not used carefully.

ton1c
Apr 30, 2005
That script starts shoutcast servers as anonymous apache users.

geetee
Feb 2, 2004

>;[

ton1c posted:

That script starts shoutcast servers as anonymous apache users.

so what

RussianManiac
Dec 27, 2005

by Ozmaugh

geetee posted:

so what

yea its kinda confusing looking at that whole buncha code trying to decipher where horror is.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
Whenever I see PHP in this thread I just accept that there is a horror and nod my head before moving swiftly onward.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Does using COM to run a program via WScript.Shell count as a horror? I don't really want to know why both that and exec are used about two lines apart.

floWenoL
Oct 23, 2002

geetee posted:

It's not a flaw. It's a potential vulnerability if not used carefully.

Does gtbot shell out like this?

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
yeah like that's a lot of php code and in any 20+ line chunk of php there's bound to be at least one horror but honestly using a shell exec command to start a server probably isn't it

geetee
Feb 2, 2004

>;[

floWenoL posted:

Does gtbot shell out like this?

gtbot is written in the magical C# language.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Plorkyeran posted:

Does using COM to run a program via WScript.Shell count as a horror? I don't really want to know why both that and exec are used about two lines apart.

COM is always a horror.

Sam.
Jan 1, 2009

"I thought we had something, Shepard. Something real."
:qq:

Flobbster posted:

Windows is always a horror.
Fixed.

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.
0.
code:
// Node that can hold anything
class ListNode{
  void * value;
public:
  // ...
  ~ListNode(){
    delete value;
  }
};

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

Mustach posted:

0.
code:
// Node that can hold anything
class ListNode{
  void * value;
public:
  // ...
  ~ListNode(){
    delete value;
  }
};

heh

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