| 679 | } |
| 680 | |
| 681 | static bool time_change(u64 *new_start, u64 prevstart, u32 number, |
| 682 | bool (*add_time)(struct tm *tm, u32 number), |
| 683 | bool day_const) |
| 684 | { |
| 685 | struct tm *tm_ptr; |
| 686 | struct tm tm; |
| 687 | time_t prev = prevstart, ret; |
| 688 | |
| 689 | tm_ptr = gmtime(&prev); |
| 690 | /* Early exit, prev cannot be represented by struct tm. */ |
| 691 | if (!tm_ptr) |
| 692 | return false; |
| 693 | tm = *tm_ptr; |
| 694 | |
| 695 | for (;;) { |
| 696 | struct tm new_tm = tm; |
| 697 | |
| 698 | /* The individual time components are int and can overflow. */ |
| 699 | if (!add_time(&new_tm, number)) |
| 700 | return false; |
| 701 | |
| 702 | ret = mktime(&new_tm); |
| 703 | |
| 704 | if (ret == (time_t)-1) |
| 705 | return false; |
| 706 | |
| 707 | /* If we overflowed that month, try one less. */ |
| 708 | if (!day_const || new_tm.tm_mday == tm.tm_mday) |
| 709 | break; |
| 710 | tm.tm_mday--; |
| 711 | } |
| 712 | |
| 713 | *new_start = ret; |
| 714 | return true; |
| 715 | } |
| 716 | |
| 717 | bool offer_period_start(u64 *start, u64 basetime, size_t n, |
| 718 | const struct recurrence *recur) |
no outgoing calls
no test coverage detected