File: aio.c

package info (click to toggle)
valgrind 1%3A3.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 176,332 kB
  • sloc: ansic: 795,029; exp: 26,134; xml: 23,472; asm: 14,393; cpp: 9,397; makefile: 7,464; sh: 6,122; perl: 5,446; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (92 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <assert.h>
#include <aio.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int x;

int main(void)
{
   #define LEN 10
   char buf[LEN];

   struct aiocb a;
   struct sigevent s;

   memset(&a, 0, sizeof(struct aiocb));
   // Not sure if the sigevent is even looked at by aio_*... just zero it.
   memset(&s, 0, sizeof(struct sigevent));

   a.aio_fildes     = -1;
   a.aio_offset     = 0;
   a.aio_buf        = NULL;
   a.aio_nbytes     = LEN;
   a.aio_reqprio    = 0;
   a.aio_sigevent   = s;
   a.aio_lio_opcode = 0;   // ignored

   //------------------------------------------------------------------------
   // The cases where aiocbp itself points to bogus memory is handled in
   // memcheck/tests/darwin/scalar.c, so we don't check that here.

   //------------------------------------------------------------------------
   // XXX: This causes an unexpected undef value error later, at the XXX mark.
   //      Not sure why, it shouldn't.
   // assert( aio_return(&a) < 0);  // (aiocbp hasn't been inited)

   //------------------------------------------------------------------------
   assert( aio_read(&a) < 0);       // invalid fd

   //------------------------------------------------------------------------
   a.aio_fildes = open("aio.c", O_RDONLY);
   assert(a.aio_fildes >= 0);

   assert( aio_read(&a) < 0);       // unaddressable aio_buf

   //------------------------------------------------------------------------
   a.aio_buf = buf;

   assert( aio_read(&a) == 0 );

   assert( aio_read(&a)  < 0 );     // (don't crash on the repeated &a)

   while (0 != aio_error(&a)) { }

   if (buf[0] == buf[9]) x++;       // undefined -- aio_return() not called yet

   assert( aio_return(&a) > 0 );    // XXX: (undefined value error here)

   if (buf[0] == buf[9]) x++;

   assert( aio_return(&a) < 0 );    // (repeated aio_return();  fails because 
                                    // Valgrind can't find &a in the table)

   //------------------------------------------------------------------------
   a.aio_buf    = 0;
   a.aio_fildes = creat("mytmpfile", S_IRUSR|S_IWUSR);
   assert(a.aio_fildes >= 0);

   assert( aio_write(&a) < 0);      // unaddressable aio_buf

   //------------------------------------------------------------------------
   a.aio_buf = buf;

   assert( aio_write(&a) == 0 );

   assert( aio_write(&a)  < 0 );    // (don't crash on the repeated &a)

   while (0 != aio_error(&a)) { }

   assert( aio_return(&a) > 0 );

   assert( aio_return(&a) < 0 );    // (repeated aio_return();  fails because 
                                    // Valgrind can't find &a in the table)

   unlink("mytmpfile");

   return x;
};