mmottl / gsl-ocaml

OCaml bindings to the GSL (GNU Scientific Library).
Other
36 stars 10 forks source link

fix invalid printf formats #2

Closed damiendoligez closed 10 years ago

damiendoligez commented 10 years ago

There are some format strings that are "invalid" in the gsl-ocaml sources.

In general, invalid formats are nonsensical format strings that were accepted in OCaml 4.01.0 and earlier, but whose semantics is unspecified. They are still accepted by the new Printf implementation of OCaml 4.02.0 but in some cases with different semantics, and they will be statically rejected by OCaml 4.03.0.

You can check for them in OCaml 4.02.0 with the flag -strict-formats.

In the case of gsl-ocaml, I think the behavior has not changed between 4.01.0 and 4.02.0. The only kind of invalid format is "%+ .3f". This is considered invalid beause the '+' flag means that positive numbers must be prefixed with a '+' character, and the ' ' flag means that positive numbers must be prefixed with a space, so these two flags are incompatible. Even though the behaviour has not changed, you should take the opportunity to review the code and fix the format. The patch changes it to "%+.3f", which keeps the behaviour unchanged, but that might still be wrong.

mmottl commented 10 years ago

Thanks!