diff src/libpam/environ.rs @ 105:13b4d2a19674

Support Rust v1.75.0. This is the version included in Ubuntu 24.04 LTS and Debian Trixie, so it's old enough to have wide penetration without being too old to get new features (Debian Stable, I love you but v1.63 is just not going to work out).
author Paul Fisher <paul@pfish.zone>
date Thu, 26 Jun 2025 00:48:51 -0400
parents dfcd96a74ac4
children 49d9e2b5c189
line wrap: on
line diff
--- a/src/libpam/environ.rs	Wed Jun 25 16:56:56 2025 -0400
+++ b/src/libpam/environ.rs	Thu Jun 26 00:48:51 2025 -0400
@@ -139,6 +139,7 @@
         }
     }
 }
+
 impl Iterator for EnvList<'_> {
     type Item = (OsString, OsString);
 
@@ -152,7 +153,7 @@
                 // SAFETY: We know we're still pointing to a valid pointer,
                 // and advancing it one more is allowed.
                 unsafe {
-                    self.current = self.current.add(1);
+                    self.current = advance(self.current);
                     ptr::drop_in_place(item as *mut EnvVar);
                 }
                 Some(ret)
@@ -167,14 +168,18 @@
         // either an item we haven't used, or to the None end.
         unsafe {
             while let Some(var_ref) = self.current.as_mut() {
+                self.current = advance(self.current);
                 ptr::drop_in_place(var_ref as *mut EnvVar);
-                self.current = self.current.add(1);
             }
             memory::free(self.start.as_ptr())
         }
     }
 }
 
+unsafe fn advance<T>(nn: NonNull<T>) -> NonNull<T> {
+    NonNull::new_unchecked(nn.as_ptr().offset(1))
+}
+
 struct EnvVar(CHeapString);
 
 impl EnvVar {
@@ -217,11 +222,11 @@
         unsafe {
             for (idx, &text) in strings.iter().enumerate() {
                 ptr::write(
-                    ptrs.add(idx).as_ptr(),
+                    ptrs.as_ptr().add(idx),
                     Some(CHeapString::new(text).unwrap()),
                 )
             }
-            ptr::write(ptrs.add(strings.len()).as_ptr(), None);
+            ptr::write(ptrs.as_ptr().add(strings.len()), None);
             EnvList::from_ptr(ptrs.cast())
         }
     }