Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Echelon9 on April 05, 2015, 08:20:59 am

Title: Code review: Oddities in debug console string parsing
Post by: Echelon9 on April 05, 2015, 08:20:59 am
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
 
Title: Re: Code review: Oddities in debug console string parsing
Post by: chief1983 on April 05, 2015, 12:07:14 pm
That does look like the intended behavior.  Question is, does the intended behavior work?  :)
Title: Re: Code review: Oddities in debug console string parsing
Post by: z64555 on April 05, 2015, 03:52:54 pm
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.
Title: Re: Code review: Oddities in debug console string parsing
Post by: AdmiralRalwood on April 05, 2015, 04:27:56 pm
Additionally, dc_required_string_either() isn't currently called anywhere, so correcting its behavior shouldn't break anything.
Title: Re: Code review: Oddities in debug console string parsing
Post by: Echelon9 on April 08, 2015, 05:45:19 pm
z64555, do you mind if I leave it to you to test and commit the patch?
Title: Re: Code review: Oddities in debug console string parsing
Post by: z64555 on April 08, 2015, 06:34:02 pm
Yeah, I can do that. I'll try to get it done soonish.
Title: [Comitted] Oddities in debug console string parsing
Post by: z64555 on April 11, 2015, 01:51:33 am
Fix committed 1130