Compile with -Wwrite-strings, fix warnings that ensueBRL-CAD
Status: ClosedTime to complete: 48 hrs Mentors: SeanTags: compile, warnings, C, C++, code quality

We hold BRL-CAD to a rather high standard of code quality.  We compile with nearly every useful warning that GCC is capable of producing and consider all warnings as errors that stop compilation.  This is done because many/most warnings are "code smells" that are eventually usually costly to ignore over time.

This task involves adding the -Wwrite-strings warning to our compilation and fixing the issues that result.  You can add the flag by editing misc/CMake/BRLCAD_CompilerFlags.cmake

Make sure you compile cleanly before beginning.  Make sure you're using a fresh SVN checkout.  See http://brlcad.org/wiki/Compiling for help.

Protip: run this to save all errors to a file so you can work on them in bulk: make -k 21 | tee build.log

Note that nearly all the errors that will result are trivially fixed by adding "const" to a struct declaration.  Submit you work as a single patch file, see http://brlcad.org/wiki/Patches

Uploaded Work
File name/URLFile sizeDate submitted
const_char_fix.patch303.4 KBJanuary 03 2013 14:56 UTC
Comments
javamonnon December 23 2012 19:26 UTCTask Claimed

I would like to work on this task.

Sean on December 23 2012 19:58 UTCTask Assigned

This task has been assigned to javamonn. You have 48 hours to complete this task, good luck!

javamonnon December 24 2012 02:21 UTCA quick question:

So, just to be sure I'm looking at the right errors here, I've added the following to the BRLCAD_CompilerFlags.cmake file:


brlcad_check_c_flag(Wwrite-strings) and brlcad_check_cxx_flag(Wwrite-strings)


and the compilation results in a fair amount of :


error: initialization discards ‘const’ qualifier from pointer target type [-Werror]


These are the errors I should fix, right? I'm just checking because I almost expected to see errors with [-Wwrite-strings] as the last part, since -Werror is its own seperate flag. 


Thanks,


Daniel

javamonnon December 24 2012 02:35 UTCOn second thought...

I just removed the brlcad_check_c_flag(Wwrite_strings) to check myself and these errors still appear, so I'm guessing these are not what I should be fixing (even thought they look to be caused by a similar problem). How exactly do I go about adding the wwrite_strings flag, since it appears there is more to it than adding the lines I already have?


Thanks for the help,


Daniel

javamonnon December 24 2012 02:56 UTCThird time is the charm...

So, now I just feel stupid. I just realized I had those two lines of code in two sepearte places in that file. When I removed them both, the errors dissapeared. So it looks like I did set that flag correctly after all, haha. I'll get to work now. 


Thanks, 


Daniel

javamonnon December 24 2012 17:55 UTCClaim Removed

The claim on this task has been removed, someone else can claim it now.

Sean on December 28 2012 08:47 UTChave the right idea

Sounds like you have/had the right idea before you unclaimed.  Instead of removing lines of code, though, you'll need to propagate 'const' in a lot of places.

gckingon December 30 2012 21:45 UTCTask Claimed

I would like to work on this task.

Harmanpreet Singh on December 31 2012 03:42 UTCTask Assigned

This task has been assigned to gcking. You have 48 hours to complete this task, good luck!

Melange on January 2 2013 03:42 UTCInitial Deadline passed

Melange has detected that the initial deadline has passed and it has set the task status to ActionNeeded. The student has 24 hours to submit the work before the task is reopened and sent back to the pool for other students to claim.

Melange on January 3 2013 03:42 UTCTask Reopened

Melange has detected that the final deadline has passed and it has reopened the task.

gckingon January 3 2013 04:52 UTCTask Claimed

I would like to work on this task.

gckingon January 3 2013 05:06 UTCJust finished my work

Can I reclaim the task and upload my work?

Harmanpreet Singh on January 3 2013 05:50 UTCTask Assigned

This task has been assigned to gcking. You have 48 hours to complete this task, good luck!

Harmanpreet Singh on January 3 2013 05:52 UTCYes

The task has been reassigned to you and you can now upload your work for review.


Good luck..!!

gckingon January 3 2013 14:56 UTCReady for review

The work on this task is ready to be reviewed.

Melange on January 5 2013 05:50 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Sean on January 5 2013 16:29 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Sean on January 5 2013 16:30 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on January 5 2013 16:37 UTCwrong way to quell

Your patch by large looks great but there is a problem that prevents the patch from being used.  Casting string literals to (char *) is no good.


That tells the compiler that it's okay to allow that memory to be edited, and that's generally a bad thing.  That's why the compiler is warning in the first place.  The "fix" is usually to make the recipient const.  If the setee really is needing to edit the string, then we need to know about those cases an review them on a case-by-case basis to see what's going on.


We can create a follow-up task so you can keep working on this if you've worked more than a few hours already (i.e., scope is off).  How long did you work on this?

gckingon January 5 2013 17:56 UTCcasting string literals

after my first compilation, I realized it is a big modification.  I had spent over 72 hours on it.  in many places, if I changed the string literals to be constant variable instead of cast to (char *), then it would have impact on the signature of some invoking function, which will propagate to other modules.  It definitely needs more time to do analysis.

Sean on January 6 2013 14:57 UTCmark as complete

The time estimate I'm looking for is actual time typing in an editor, not how long including food breaks and sleeping.. ;)  A better estimate perhaps is how long do you think it would take you to sit down and retype everything you just did for this patch if you had to do it again?  Would that be 3 non-stop hours of typing?  6 hours?  12 hours?


Either way, go ahead and mark as complete.  We can try to create follow-up task before GCI ends to break the task up in chunks.

Sean on January 6 2013 14:57 UTCDeadline extended

The deadline of the task has been extended with 0 days and 12 hours.

gckingon January 6 2013 19:05 UTCmy mistake

it is my mistake that gave you the incorrect working hours, because when task is assigned, it is based on calendar days, I was confused by that. but I will try my best to work on this.

gckingon January 6 2013 22:05 UTCReady for review

The work on this task is ready to be reviewed.

Melange on January 7 2013 11:58 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Daniel Rossberg on January 7 2013 13:15 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on January 8 2013 09:06 UTChow long?

gcking, How long do you think this patch would take if you had to do it again?  How many hours of typing?



gckingon January 9 2013 00:13 UTC10-12 hours

Sorry for the late reply, I just finished some school work.  I guess 10 hours should be ok.