Author Topic: Code review: Oddities in debug console string parsing  (Read 1889 times)

0 Members and 1 Guest are viewing this topic.

Offline Echelon9

  • 210
Code review: Oddities in debug console string parsing
For those that aren't aware, the FS2Open engine has a debug console. Recent versions of Clang compiler (i.e. 3.5+) report a warning on some very odd code within consoleparse.cpp:

Code: [Select]
if (strncmp(str1, Cp, strlen(str1) == 0)) {
                ^ Size argument in 'strncmp' call is a comparison.
                ^ Fix-it: Did you mean to compare the result of 'strncmp' instead?
// Do stuff

The suggested patch is as follows:

Code: [Select]
Index: code/debugconsole/consoleparse.cpp
===================================================================
--- code/debugconsole/consoleparse.cpp (revision 11296)
+++ code/debugconsole/consoleparse.cpp (working copy)
@@ -492,10 +492,10 @@
 
  dc_ignore_gray_space();
 
- if (strncmp(str1, Cp, strlen(str1) == 0)) {
+ if (strncmp(str1, Cp, strlen(str1)) == 0) {
  str_found = str1;
  i = 0;
- } else if (strncmp(str2, Cp, strlen(str2) == 0)) {
+ } else if (strncmp(str2, Cp, strlen(str2)) == 0) {
  str_found = str2;
  i = 1;
  }
@@ -563,7 +563,7 @@
 {
  dc_ignore_gray_space();
 
- if (strncmp(pstr, Cp, strlen(pstr) != 0)) {
+ if (strncmp(pstr, Cp, strlen(pstr)) != 0) {
  return false;
  } // Else, optional string was found
 

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: Code review: Oddities in debug console string parsing
That does look like the intended behavior.  Question is, does the intended behavior work?  :)
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

  

Offline z64555

  • 210
  • Self-proclaimed controls expert
    • Steam
Re: Code review: Oddities in debug console string parsing
how the hell did I miss that. lol.  :banghead:

[Edit] Just for clarification, Yes, that is the intended behavior of the dc_required_string functions.
« Last Edit: April 05, 2015, 04:03:16 pm by z64555 »
Secure the Source, Contain the Code, Protect the Project
chief1983

------------
funtapaz: Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Juche.
z64555: s/J/Do
BotenAlfred: <funtapaz> Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Douche.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Code review: Oddities in debug console string parsing
Additionally, dc_required_string_either() isn't currently called anywhere, so correcting its behavior shouldn't break anything.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Echelon9

  • 210
Re: Code review: Oddities in debug console string parsing
z64555, do you mind if I leave it to you to test and commit the patch?

 

Offline z64555

  • 210
  • Self-proclaimed controls expert
    • Steam
Re: Code review: Oddities in debug console string parsing
Yeah, I can do that. I'll try to get it done soonish.
Secure the Source, Contain the Code, Protect the Project
chief1983

------------
funtapaz: Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Juche.
z64555: s/J/Do
BotenAlfred: <funtapaz> Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Douche.

 

Offline z64555

  • 210
  • Self-proclaimed controls expert
    • Steam
[Comitted] Oddities in debug console string parsing
Fix committed 1130
Secure the Source, Contain the Code, Protect the Project
chief1983

------------
funtapaz: Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Juche.
z64555: s/J/Do
BotenAlfred: <funtapaz> Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Douche.