Sinisterly
What NOT to do when coding - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C)
+--- Thread: What NOT to do when coding (/Thread-What-NOT-to-do-when-coding)



What NOT to do when coding - phyrrus9 - 10-21-2017

So, take a look at this union....it makes no sense...on top of that, the author of this code is doing some weird shit with the ptr field... when i told him that this is a massive issue, and causes a buffer overflow no matter how he uses it, he didn't get it and kept describing that it's "one way to implement std:Confusedtring"

Have a look for yourselves:
[Image: guArI8z.png]

Notice how my second string has overflowed and is now in the .text segment, pretty close to the executable code for the function main? Pretty cool huh?

He still doesn't understand that this is a bug, and a pretty fucking awesome security vulnerability if you as me, I wish Apple wrote code like this Tongue


RE: What NOT to do when coding - Nil - 10-21-2017

Hmmm. Haven't looked at C code in years and having trouble following this. Firstly, I'm a huge discourager of acronyms and abbreviations (ptr, s2, str, bug) unless they are almost universally known what it means and is not ambiguous in any domain. Could you explain the duplicate check in print string? I'm sure it's just my unfamiliarity with the syntax.


RE: What NOT to do when coding - phyrrus9 - 10-21-2017

(10-21-2017, 02:17 PM)God Wrote: Hmmm. Haven't looked at C code in years and having trouble following this. Firstly, I'm a huge discourager of acronyms and abbreviations (ptr, s2, str, bug) unless they are almost universally known what it means and is not ambiguous in any domain. Could you explain the duplicate check in print string? I'm sure it's just my unfamiliarity with the syntax.

It's not a duplicate check, it's the same check used for the second argument.


RE: What NOT to do when coding - Nil - 10-21-2017

(10-21-2017, 02:19 PM)phyrrus9 Wrote:
(10-21-2017, 02:17 PM)God Wrote: Hmmm. Haven't looked at C code in years and having trouble following this. Firstly, I'm a huge discourager of acronyms and abbreviations (ptr, s2, str, bug) unless they are almost universally known what it means and is not ambiguous in any domain.  Could you explain the duplicate check in print string? I'm sure it's just my unfamiliarity with the syntax.

It's not a duplicate check, it's the same check used for the second argument.

Okay I see the %p and wasn't sure if that was just a fancy way of printing the string again but I see that it's the address of a pointer from what I gathered real quick.


RE: What NOT to do when coding - phyrrus9 - 10-21-2017

(10-21-2017, 02:32 PM)God Wrote:
(10-21-2017, 02:19 PM)phyrrus9 Wrote:
(10-21-2017, 02:17 PM)God Wrote: Hmmm. Haven't looked at C code in years and having trouble following this. Firstly, I'm a huge discourager of acronyms and abbreviations (ptr, s2, str, bug) unless they are almost universally known what it means and is not ambiguous in any domain.  Could you explain the duplicate check in print string? I'm sure it's just my unfamiliarity with the syntax.

It's not a duplicate check, it's the same check used for the second argument.

Okay I see the %p and wasn't sure if that was just a fancy way of printing the string again but I see that it's the address of a pointer from what I gathered real quick.

Yeah. The very bad programmer who wrote this is using ternaries to make themself look smarter (in practice, you should avoid using them)

This all started because he was saying he understood how to use unions, and then felt like he had to prove it to me, and whipped up literally the most useless union I have ever seen. The union he made has absolutely no purpose, he couldn't even describe to me what he intended it to do, and wasn't able to understand at all what it actually does.


RE: What NOT to do when coding - Nil - 10-21-2017

(10-21-2017, 02:36 PM)phyrrus9 Wrote:
(10-21-2017, 02:32 PM)God Wrote:
(10-21-2017, 02:19 PM)phyrrus9 Wrote: It's not a duplicate check, it's the same check used for the second argument.

Okay I see the %p and wasn't sure if that was just a fancy way of printing the string again but I see that it's the address of a pointer from what I gathered real quick.

Yeah. The very bad programmer who wrote this is using ternaries to make themself look smarter (in practice, you should avoid using them)

This all started because he was saying he understood how to use unions, and then felt like he had to prove it to me, and whipped up literally the most useless union I have ever seen. The union he made has absolutely no purpose, he couldn't even describe to me what he intended it to do, and wasn't able to understand at all what it actually does.

Haha, I wasn't familiar with unions until this thread. Actually thought before looking at the code we were talking about set theory, lol. Anyway, is this particular person a contractor you hired? And yes, ternaries aren't seen too often, but I have been implementing them with React, where that seems to be a favored way when embedding JS with markup.


RE: What NOT to do when coding - phyrrus9 - 10-21-2017

(10-21-2017, 02:56 PM)God Wrote:
(10-21-2017, 02:36 PM)phyrrus9 Wrote:
(10-21-2017, 02:32 PM)God Wrote: Okay I see the %p and wasn't sure if that was just a fancy way of printing the string again but I see that it's the address of a pointer from what I gathered real quick.

Yeah. The very bad programmer who wrote this is using ternaries to make themself look smarter (in practice, you should avoid using them)

This all started because he was saying he understood how to use unions, and then felt like he had to prove it to me, and whipped up literally the most useless union I have ever seen. The union he made has absolutely no purpose, he couldn't even describe to me what he intended it to do, and wasn't able to understand at all what it actually does.

Haha, I wasn't familiar with unions until this thread. Actually thought before looking at the code we were talking about set theory, lol. Anyway, is this particular person a contractor you hired? And yes, ternaries aren't seen too often, but I have been implementing them with React, where that seems to be a favored way when embedding JS with markup.

No, this is a skid from the SL discord chat. I won't disclose the guy's name, don't want to rep smear him over it.