]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dns: fix clippy lint warnings
authorShivani Bhardwaj <shivani@oisf.net>
Fri, 13 Dec 2024 07:03:08 +0000 (12:33 +0530)
committerJason Ish <jason.ish@oisf.net>
Tue, 18 Feb 2025 21:46:10 +0000 (15:46 -0600)
Fix vector lint issues:
- same_item_push
- vec_init_then_push

(cherry picked from commit 2c0d3b83c442fc751f8418f3f4833d86cdd495d3)

rust/src/dns/parser.rs

index c98ba05e26b23927c28296674bc9a30ada224048..d31dec82126c1a31a6d272a2866f2211bf3324de 100644 (file)
@@ -995,11 +995,10 @@ mod tests {
     fn test_dns_parse_name_truncated() {
         // Generate a non-compressed hostname over our maximum of 1024.
         let mut buf: Vec<u8> = vec![];
-        for _ in 0..17 {
+
+        for i in 1..18 {
             buf.push(0b0011_1111);
-            for _ in 0..63 {
-                buf.push(b'a');
-            }
+            buf.resize(i * 64, b'a');
         }
 
         let mut flags = DNSNameFlags::default();
@@ -1026,20 +1025,21 @@ mod tests {
 
     #[test]
     fn test_dns_parse_name_truncated_max_segments_with_pointer() {
-        let mut buf: Vec<u8> = vec![];
-
-        // "a" at the beginning of the buffer.
-        buf.push(0b0000_0001);
-        buf.push(b'a');
-
-        // Followed by a pointer back to the beginning.
-        buf.push(0b1100_0000);
-        buf.push(0b0000_0000);
-
-        // The start of the name, which is pointer to the beginning of
-        // the buffer.
-        buf.push(0b1100_0000);
-        buf.push(0b000_0000);
+        #[rustfmt::skip]
+        let buf: Vec<u8> = vec![
+            // "a" at the beginning of the buffer.
+            0b0000_0001,
+            b'a',
+
+            // Followed by a pointer back to the beginning.
+            0b1100_0000,
+            0b0000_0000,
+
+            // The start of the name, which is pointer to the beginning of
+            // the buffer.
+            0b1100_0000,
+            0b000_0000
+        ];
 
         let mut flags = DNSNameFlags::default();
         let (_rem, name) = dns_parse_name(&buf[4..], &buf, &mut flags).unwrap();
@@ -1049,9 +1049,7 @@ mod tests {
 
     #[test]
     fn test_dns_parse_name_self_reference() {
-        let mut buf = vec![];
-        buf.push(0b1100_0000);
-        buf.push(0b0000_0000);
+        let buf = vec![0b1100_0000, 0b0000_0000];
         let mut flags = DNSNameFlags::default();
         assert!(dns_parse_name(&buf, &buf, &mut flags).is_err());
     }