luaur_analysis/methods/
lint_format_string_check_date_format.rs1use crate::records::lint_format_string::LintFormatString;
2use core::ffi::c_char;
3
4impl LintFormatString {
5 pub fn check_date_format(&self, data: *const c_char, size: usize) -> *const c_char {
6 let options = b"aAbBcdHIjmMpSUwWxXyYzZ";
7
8 let mut i = 0;
9 while i < size {
10 let ch = unsafe { *data.add(i) };
11 if ch == b'%' as i8 {
12 i += 1;
13
14 if i == size {
15 return c"unfinished replacement".as_ptr();
16 }
17
18 let next_ch = unsafe { *data.add(i) };
19 if next_ch != b'%' as i8 && !options.contains(&(next_ch as u8)) {
20 return c"unexpected replacement character; must be a date format specifier or %".as_ptr();
21 }
22 }
23
24 if unsafe { *data.add(i) } == 0 {
25 return c"date format can not contain null characters".as_ptr();
26 }
27 i += 1;
28 }
29
30 core::ptr::null()
31 }
32}