Skip to content

Commit 9c9af2c

Browse files
Fix safety of sockopt helper traits
1 parent 648a9db commit 9c9af2c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/sys/socket/sockopt.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -178,37 +178,37 @@ sockopt_impl!(GetOnly, OriginalDst, libc::SOL_IP, libc::SO_ORIGINAL_DST, libc::s
178178
*
179179
*/
180180

181-
trait Get<T> {
181+
unsafe trait Get<T> {
182182
unsafe fn blank() -> Self;
183-
unsafe fn ffi_ptr(&mut self) -> *mut c_void;
184-
unsafe fn ffi_len(&mut self) -> *mut socklen_t;
183+
fn ffi_ptr(&mut self) -> *mut c_void;
184+
fn ffi_len(&mut self) -> *mut socklen_t;
185185
unsafe fn unwrap(self) -> T;
186186
}
187187

188-
trait Set<'a, T> {
188+
unsafe trait Set<'a, T> {
189189
fn new(val: &'a T) -> Self;
190-
unsafe fn ffi_ptr(&self) -> *const c_void;
191-
unsafe fn ffi_len(&self) -> socklen_t;
190+
fn ffi_ptr(&self) -> *const c_void;
191+
fn ffi_len(&self) -> socklen_t;
192192
}
193193

194194
struct GetStruct<T> {
195195
len: socklen_t,
196196
val: T,
197197
}
198198

199-
impl<T> Get<T> for GetStruct<T> {
199+
unsafe impl<T> Get<T> for GetStruct<T> {
200200
unsafe fn blank() -> Self {
201201
GetStruct {
202202
len: mem::size_of::<T>() as socklen_t,
203203
val: mem::zeroed(),
204204
}
205205
}
206206

207-
unsafe fn ffi_ptr(&mut self) -> *mut c_void {
207+
fn ffi_ptr(&mut self) -> *mut c_void {
208208
&mut self.val as *mut T as *mut c_void
209209
}
210210

211-
unsafe fn ffi_len(&mut self) -> *mut socklen_t {
211+
fn ffi_len(&mut self) -> *mut socklen_t {
212212
&mut self.len
213213
}
214214

@@ -222,16 +222,16 @@ struct SetStruct<'a, T: 'static> {
222222
ptr: &'a T,
223223
}
224224

225-
impl<'a, T> Set<'a, T> for SetStruct<'a, T> {
225+
unsafe impl<'a, T> Set<'a, T> for SetStruct<'a, T> {
226226
fn new(ptr: &'a T) -> SetStruct<'a, T> {
227227
SetStruct { ptr: ptr }
228228
}
229229

230-
unsafe fn ffi_ptr(&self) -> *const c_void {
230+
fn ffi_ptr(&self) -> *const c_void {
231231
self.ptr as *const T as *const c_void
232232
}
233233

234-
unsafe fn ffi_len(&self) -> socklen_t {
234+
fn ffi_len(&self) -> socklen_t {
235235
mem::size_of::<T>() as socklen_t
236236
}
237237
}
@@ -241,19 +241,19 @@ struct GetBool {
241241
val: c_int,
242242
}
243243

244-
impl Get<bool> for GetBool {
244+
unsafe impl Get<bool> for GetBool {
245245
unsafe fn blank() -> Self {
246246
GetBool {
247247
len: mem::size_of::<c_int>() as socklen_t,
248248
val: mem::zeroed(),
249249
}
250250
}
251251

252-
unsafe fn ffi_ptr(&mut self) -> *mut c_void {
252+
fn ffi_ptr(&mut self) -> *mut c_void {
253253
&mut self.val as *mut c_int as *mut c_void
254254
}
255255

256-
unsafe fn ffi_len(&mut self) -> *mut socklen_t {
256+
fn ffi_len(&mut self) -> *mut socklen_t {
257257
&mut self.len
258258
}
259259

@@ -267,16 +267,16 @@ struct SetBool {
267267
val: c_int,
268268
}
269269

270-
impl<'a> Set<'a, bool> for SetBool {
270+
unsafe impl<'a> Set<'a, bool> for SetBool {
271271
fn new(val: &'a bool) -> SetBool {
272272
SetBool { val: if *val { 1 } else { 0 } }
273273
}
274274

275-
unsafe fn ffi_ptr(&self) -> *const c_void {
275+
fn ffi_ptr(&self) -> *const c_void {
276276
&self.val as *const c_int as *const c_void
277277
}
278278

279-
unsafe fn ffi_len(&self) -> socklen_t {
279+
fn ffi_len(&self) -> socklen_t {
280280
mem::size_of::<c_int>() as socklen_t
281281
}
282282
}
@@ -286,19 +286,19 @@ struct GetU8 {
286286
val: uint8_t,
287287
}
288288

289-
impl Get<u8> for GetU8 {
289+
unsafe impl Get<u8> for GetU8 {
290290
unsafe fn blank() -> Self {
291291
GetU8 {
292292
len: mem::size_of::<uint8_t>() as socklen_t,
293293
val: mem::zeroed(),
294294
}
295295
}
296296

297-
unsafe fn ffi_ptr(&mut self) -> *mut c_void {
297+
fn ffi_ptr(&mut self) -> *mut c_void {
298298
&mut self.val as *mut uint8_t as *mut c_void
299299
}
300300

301-
unsafe fn ffi_len(&mut self) -> *mut socklen_t {
301+
fn ffi_len(&mut self) -> *mut socklen_t {
302302
&mut self.len
303303
}
304304

@@ -312,16 +312,16 @@ struct SetU8 {
312312
val: uint8_t,
313313
}
314314

315-
impl<'a> Set<'a, u8> for SetU8 {
315+
unsafe impl<'a> Set<'a, u8> for SetU8 {
316316
fn new(val: &'a u8) -> SetU8 {
317317
SetU8 { val: *val as uint8_t }
318318
}
319319

320-
unsafe fn ffi_ptr(&self) -> *const c_void {
320+
fn ffi_ptr(&self) -> *const c_void {
321321
&self.val as *const uint8_t as *const c_void
322322
}
323323

324-
unsafe fn ffi_len(&self) -> socklen_t {
324+
fn ffi_len(&self) -> socklen_t {
325325
mem::size_of::<c_int>() as socklen_t
326326
}
327327
}
@@ -331,19 +331,19 @@ struct GetUsize {
331331
val: c_int,
332332
}
333333

334-
impl Get<usize> for GetUsize {
334+
unsafe impl Get<usize> for GetUsize {
335335
unsafe fn blank() -> Self {
336336
GetUsize {
337337
len: mem::size_of::<c_int>() as socklen_t,
338338
val: mem::zeroed(),
339339
}
340340
}
341341

342-
unsafe fn ffi_ptr(&mut self) -> *mut c_void {
342+
fn ffi_ptr(&mut self) -> *mut c_void {
343343
&mut self.val as *mut c_int as *mut c_void
344344
}
345345

346-
unsafe fn ffi_len(&mut self) -> *mut socklen_t {
346+
fn ffi_len(&mut self) -> *mut socklen_t {
347347
&mut self.len
348348
}
349349

@@ -357,16 +357,16 @@ struct SetUsize {
357357
val: c_int,
358358
}
359359

360-
impl<'a> Set<'a, usize> for SetUsize {
360+
unsafe impl<'a> Set<'a, usize> for SetUsize {
361361
fn new(val: &'a usize) -> SetUsize {
362362
SetUsize { val: *val as c_int }
363363
}
364364

365-
unsafe fn ffi_ptr(&self) -> *const c_void {
365+
fn ffi_ptr(&self) -> *const c_void {
366366
&self.val as *const c_int as *const c_void
367367
}
368368

369-
unsafe fn ffi_len(&self) -> socklen_t {
369+
fn ffi_len(&self) -> socklen_t {
370370
mem::size_of::<c_int>() as socklen_t
371371
}
372372
}

0 commit comments

Comments
 (0)