Opened 9 years ago
Closed 9 years ago
#9216 closed Bugs (fixed)
format_date_parser::parse_date reads off end of format_str if it ends with a %
| Reported by: | Owned by: | Marshall Clow | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | date_time | 
| Version: | Boost 1.54.0 | Severity: | Problem | 
| Keywords: | Cc: | 
Description
If boost::format_date_parser::parse_date is given a format_str such as "%" then the loop in date_time\format_date_parser.hpp:
    while (itr != format_str.end() && (sitr != stream_end)) {
      if (*itr == '%') {
        itr++;
        if (*itr != '%') { // <<< ERROR here
          switch(*itr) {
          case 'a': 
tries to dereference the one-past-the-end character on the line marked.
With a debugging iterator (eg MSVC) this causes runtime failure.
Change History (8)
comment:1 by , 9 years ago
| Owner: | set to | 
|---|
comment:2 by , 9 years ago
| Component: | None → date_time | 
|---|---|
| Status: | new → assigned | 
comment:3 by , 9 years ago
comment:4 by , 9 years ago
Thanks Marshall, I can confirm that making the code change fixes the specific problem. (I had hoped to have time to post a solution myself, but...)
However, I note that the same code pattern appears elsewhere in this header - in the
- parse_month
- parse_weekday
- and parse_year
methods in this header file; and also in time_facet.hpp in two of the implementations of time_input_facet::get.
The same fix needs to be applied to these places too.
comment:5 by , 9 years ago
Thanks Roger.
I had found the other three places in this file, but hadn't looked in other files - will check.
comment:6 by , 9 years ago
comment:8 by , 9 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | assigned → closed | 


Roger -
Can you make the following change to your local install and re-run your test?
while (itr != format_str.end() && (sitr != stream_end)) { if (*itr == '%') { - itr++; + if ( ++itr == format_str.end()) break; if (*itr != '%') { // <<< ERROR hereThanks!