(sr: &SourceRange)
| 194 | } |
| 195 | |
| 196 | pub fn get_header_code_content(sr: &SourceRange) -> Result<String> { |
| 197 | if let Some(begin_loc) = &sr.begin.spelling_loc { |
| 198 | if let Some(end_loc) = &sr.end.spelling_loc { |
| 199 | if begin_loc.file.as_ref() != end_loc.file.as_ref() { |
| 200 | eyre::bail!("unable to get the source code range: {sr:?}") |
| 201 | } |
| 202 | let src_file = std::path::PathBuf::from(begin_loc.file.clone().to_string()); |
| 203 | let (begin, end) = get_header_code_range(sr)?; |
| 204 | let mut f = std::fs::File::options().read(true).open(src_file)?; |
| 205 | f.seek(std::io::SeekFrom::Start(begin as u64))?; |
| 206 | if end <= begin { |
| 207 | eyre::bail!("unable to get the source code range: {sr:?}") |
| 208 | } |
| 209 | if end_loc.line < begin_loc.line { |
| 210 | eyre::bail!("unable to get the source code range: {sr:?}") |
| 211 | } |
| 212 | if end_loc.line - begin_loc.line >= 10 { |
| 213 | eyre::bail!("unable to get the source code range: {sr:?}") |
| 214 | } |
| 215 | let count = end - begin; |
| 216 | let count = min(count, 100); |
| 217 | let mut buf = vec![0; count]; |
| 218 | f.read_exact(buf.as_mut_slice())?; |
| 219 | return Ok(String::from_utf8_lossy(&buf).to_string()); |
| 220 | } |
| 221 | } |
| 222 | eyre::bail!("unable to get the file name of this sr") |
| 223 | } |
| 224 | |
| 225 | /// Get the end source file location of inserted fuzzer shim. |
| 226 | /// Any fuzzzer variables should be initialized before this loc (inside the fuzzer shim). |
no test coverage detected