@@ -216,6 +216,87 @@ public class IoctlData : GLib.Object {
216
216
Posix . memcpy(&data[offset], new_data, new_data. length);
217
217
}
218
218
219
+ /**
220
+ * umockdev_ioctl_get_int:
221
+ * @self: A #UMockdevIoctlData
222
+ *
223
+ * Return data as integer. This avoids problems with unaligned memory.
224
+ */
225
+ public int get_int () {
226
+ int value = 0 ; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
227
+ Posix . memcpy(&value , data, sizeof(int ));
228
+ return value ;
229
+ }
230
+
231
+ /**
232
+ * umockdev_ioctl_set_int:
233
+ * @self: A #UMockdevIoctlData
234
+ * @value: Value to set
235
+ *
236
+ * Set data to given value. This avoids problems with unaligned memory.
237
+ */
238
+ public void set_int (int value ) {
239
+ Posix . memcpy(data, &value , sizeof(int ));
240
+ }
241
+
242
+ /**
243
+ * umockdev_ioctl_set_uint32:
244
+ * @self: A #UMockdevIoctlData
245
+ * @value: Value to set
246
+ *
247
+ * Set data to given value. This avoids problems with unaligned memory.
248
+ */
249
+ public void set_uint32 (uint32 value ) {
250
+ Posix . memcpy(data, &value , sizeof(uint32 ));
251
+ }
252
+
253
+ /**
254
+ * umockdev_ioctl_get_ulong:
255
+ * @self: A #UMockdevIoctlData
256
+ *
257
+ * Return data as ulong. This avoids problems with unaligned memory.
258
+ */
259
+ public ulong get_ulong () {
260
+ ulong value = 0 ; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
261
+ Posix . memcpy(&value , data, sizeof(ulong ));
262
+ return value ;
263
+ }
264
+
265
+ /**
266
+ * umockdev_ioctl_set_ulong:
267
+ * @self: A #UMockdevIoctlData
268
+ * @value: Value to set
269
+ *
270
+ * Set data to given value. This avoids problems with unaligned memory.
271
+ */
272
+ public void set_ulong (ulong value ) {
273
+ Posix . memcpy(data, &value , sizeof(ulong ));
274
+ }
275
+
276
+ /**
277
+ * umockdev_ioctl_get_long:
278
+ * @self: A #UMockdevIoctlData
279
+ *
280
+ * Return data as long. This avoids problems with unaligned memory.
281
+ */
282
+ public long get_long () {
283
+ long value = 0 ; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
284
+ Posix . memcpy(&value , data, sizeof(long ));
285
+ return value ;
286
+ }
287
+
288
+ /**
289
+ * umockdev_ioctl_get_pointer:
290
+ * @self: A #UMockdevIoctlData
291
+ *
292
+ * Return data as pointer. This avoids problems with unaligned memory.
293
+ */
294
+ public void * get_pointer () {
295
+ void * value = null ; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
296
+ Posix . memcpy(&value , data, sizeof(void * ));
297
+ return value ;
298
+ }
299
+
219
300
/**
220
301
* umockdev_ioctl_retrieve:
221
302
* @self: A #UMockdevIoctlData
@@ -934,7 +1015,7 @@ internal class IoctlTreeHandler : IoctlBase {
934
1015
} else {
935
1016
Posix . errno = Posix . ENOTTY ;
936
1017
}
937
- last = tree. execute(last, request, * ( void ** ) client. arg. data , ref ret);
1018
+ last = tree. execute(last, request, client. arg. get_pointer() , ref ret);
938
1019
my_errno = Posix . errno;
939
1020
Posix . errno = 0 ;
940
1021
if (last != null )
@@ -955,7 +1036,7 @@ internal class IoctlTreeHandler : IoctlBase {
955
1036
* This should only happen for REAPURB, but it does not hurt to
956
1037
* just always check.
957
1038
*/
958
- if (* ( void ** ) data. data == (void * ) last_submit_urb. data) {
1039
+ if (data. get_pointer() == (void * ) last_submit_urb. data) {
959
1040
data. set_ptr(0 , last_submit_urb);
960
1041
961
1042
last_submit_urb = null ;
@@ -1062,7 +1143,7 @@ internal class IoctlTreeRecorder : IoctlBase {
1062
1143
}
1063
1144
1064
1145
/* Record */
1065
- node = new IoctlTree .Tree .from_bin(request, * ( void ** ) client. arg. data , ret);
1146
+ node = new IoctlTree .Tree .from_bin(request, client. arg. get_pointer() , ret);
1066
1147
if (node != null ) {
1067
1148
tree. insert((owned ) node);
1068
1149
}
0 commit comments