[m-rev.] diff: Fix an unescaped '%' in a format string.

Paul Bone pbone at csse.unimelb.edu.au
Tue Jul 12 05:49:07 AEST 2011


Julien, can you put this on the release branch?

Thanks.

--

Fix an unescaped '%' in the help message's format string,

deep_profiler/mdprof_feedback.m:
    As above.

    Refactor this code so that the compiler can check that the format string
    and arguments make sense.

Index: deep_profiler/mdprof_feedback.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/mdprof_feedback.m,v
retrieving revision 1.40
diff -u -p -b -r1.40 mdprof_feedback.m
--- deep_profiler/mdprof_feedback.m	3 May 2011 04:35:00 -0000	1.40
+++ deep_profiler/mdprof_feedback.m	11 Jul 2011 19:43:15 -0000
@@ -207,9 +207,9 @@ create_feedback_report(feedback_data_can
         Parameters, Conjs), Report) :-
     create_feedback_autopar_report(Parameters, Conjs, Report).
 
-:- func help_message = string.
+:- func help_message(string) = string.
 
-help_message =
+help_message(ProgName) = format(
 "Usage: %s [<options>] <input> <output>
        %s <output>
        %s --help
@@ -294,7 +294,7 @@ help_message =
                 feedback tool will accept a parallelization. It must be
                 a floating point number, which must be at least 1.0.
                 If it is e.g. 1.02, then the feedback tool will ignore
-                parallelizations that promise less than a 2% local speedup.
+                parallelizations that promise less than a 2%% local speedup.
     --ipar-best-par-alg <alg>
                 Select which algorithm to use to find the best way to
                 parallelise a conjunction.  The available algorithms are:
@@ -319,13 +319,15 @@ help_message =
                 parallelism.  This option uses the implicit parallelism
                 settings above.
 
-".
+",
+    % This is obviously redundant but by spelling it out we allow the compiler
+    % to check that the format string and arguments make sense.
+    [s(ProgName), s(ProgName), s(ProgName), s(ProgName)]).
 
 :- pred write_help_message(string::in, io::di, io::uo) is det.
 
 write_help_message(ProgName, !IO) :-
-    Message = help_message,
-    io.format(Message, duplicate(4, s(ProgName)), !IO).
+    io.write_string(help_message(ProgName), !IO).
 
 :- pred write_version_message(string::in, io::di, io::uo) is det.
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20110712/e8d11285/attachment.sig>


More information about the reviews mailing list