SQLite

Check-in [f101c46cf8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work around compilers that do not understand flexible arrays, in the recovery extension and in the fuzzcheck test module.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | flex-array
Files: files | file ages | folders
SHA3-256: f101c46cf83e532fd33034abccba496bf395ef10c161af003211614d6581d5eb
User & Date: drh 2025-03-15 19:00:46.484
Context
2025-03-15
19:55
Make use of the C99 flexible array feature, when available, so that the -fsanitize=bounds-strict option can be used, when available. Forum thread 311dbf9a1c. (check-in: d4307a0d43 user: drh tags: trunk)
19:00
Work around compilers that do not understand flexible arrays, in the recovery extension and in the fuzzcheck test module. (Closed-Leaf check-in: f101c46cf8 user: drh tags: flex-array)
18:26
Fix alignment problems on Linux with -m32 and on Mac PPC. (check-in: 8a91aeca60 user: drh tags: flex-array)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/recover/sqlite3recover.c.
29
30
31
32
33
34
35










36
37
38
39
40
41
42
#endif
int sqlite3_dbdata_init(sqlite3*, char**, const sqlite3_api_routines*);

typedef unsigned int u32;
typedef unsigned char u8;
typedef sqlite3_int64 i64;











typedef struct RecoverTable RecoverTable;
typedef struct RecoverColumn RecoverColumn;

/*
** When recovering rows of data that can be associated with table
** definitions recovered from the sqlite_schema table, each table is
** represented by an instance of the following object.







>
>
>
>
>
>
>
>
>
>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#endif
int sqlite3_dbdata_init(sqlite3*, char**, const sqlite3_api_routines*);

typedef unsigned int u32;
typedef unsigned char u8;
typedef sqlite3_int64 i64;

/*
** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
** to avoid complaints from -fsanitize=strict-bounds.
*/
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEXARRAY
#else
# define FLEXARRAY 1
#endif

typedef struct RecoverTable RecoverTable;
typedef struct RecoverColumn RecoverColumn;

/*
** When recovering rows of data that can be associated with table
** definitions recovered from the sqlite_schema table, each table is
** represented by an instance of the following object.
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
**   false if it is clear:
**
**       (aElem[iKey/32] & (1 << (iKey%32))) ? 1 : 0
*/
typedef struct RecoverBitmap RecoverBitmap;
struct RecoverBitmap {
  i64 nPg;                        /* Size of bitmap */
  u32 aElem[];                    /* Array of 32-bit bitmasks */
};

/* Size in bytes of a RecoverBitmap object sufficient to cover 32 pages */
#define SZ_RECOVERBITMAP_32  (16)

/*
** State variables (part of the sqlite3_recover structure) used while







|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
**   false if it is clear:
**
**       (aElem[iKey/32] & (1 << (iKey%32))) ? 1 : 0
*/
typedef struct RecoverBitmap RecoverBitmap;
struct RecoverBitmap {
  i64 nPg;                        /* Size of bitmap */
  u32 aElem[FLEXARRAY];           /* Array of 32-bit bitmasks */
};

/* Size in bytes of a RecoverBitmap object sufficient to cover 32 pages */
#define SZ_RECOVERBITMAP_32  (16)

/*
** State variables (part of the sqlite3_recover structure) used while
Changes to test/fuzzcheck.c.
84
85
86
87
88
89
90





91
92
93
94
95
96
97
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
#include "sqlite3.h"
#include "sqlite3recover.h"
#define ISSPACE(X) isspace((unsigned char)(X))
#define ISDIGIT(X) isdigit((unsigned char)(X))







#ifdef __unix__
# include <signal.h>
# include <unistd.h>
#endif








>
>
>
>
>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
#include "sqlite3.h"
#include "sqlite3recover.h"
#define ISSPACE(X) isspace((unsigned char)(X))
#define ISDIGIT(X) isdigit((unsigned char)(X))
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEXARRAY
#else
# define FLEXARRAY 1
#endif


#ifdef __unix__
# include <signal.h>
# include <unistd.h>
#endif

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
*/
typedef struct Blob Blob;
struct Blob {
  Blob *pNext;            /* Next in a list */
  int id;                 /* Id of this Blob */
  int seq;                /* Sequence number */
  int sz;                 /* Size of this Blob in bytes */
  unsigned char a[];      /* Blob content.  Extra space allocated as needed. */
};

/* Size in bytes of a Blob object sufficient to store N byte of content */
#define SZ_BLOB(N) (offsetof(Blob,a) + (((N)+7)&~7))

/*
** Maximum number of files in the in-memory virtual filesystem.







|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
*/
typedef struct Blob Blob;
struct Blob {
  Blob *pNext;            /* Next in a list */
  int id;                 /* Id of this Blob */
  int seq;                /* Sequence number */
  int sz;                 /* Size of this Blob in bytes */
  unsigned char a[FLEXARRAY]; /* Blob content. Allocated as needed. */
};

/* Size in bytes of a Blob object sufficient to store N byte of content */
#define SZ_BLOB(N) (offsetof(Blob,a) + (((N)+7)&~7))

/*
** Maximum number of files in the in-memory virtual filesystem.