Skip to content

Commit 980d2a2

Browse files
committed
scan-build: work around optin.performance.Padding
Since the layout has to be preserved, padding is added.
1 parent b28eadc commit 980d2a2

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

htp/htp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ struct htp_tx_t {
221221
*/
222222
int is_config_shared;
223223

224+
SCAN_BUILD_X64_PADDING(int pad0);
225+
224226
/** The user data associated with this transaction. */
225227
void *user_data;
226228

@@ -230,6 +232,8 @@ struct htp_tx_t {
230232
/** Contains a count of how many empty lines were skipped before the request line. */
231233
unsigned int request_ignored_lines;
232234

235+
SCAN_BUILD_X64_PADDING(int pad1);
236+
233237
/** The first line of this request. */
234238
bstr *request_line;
235239

@@ -239,6 +243,8 @@ struct htp_tx_t {
239243
/** Request method, as number. Available only if we were able to recognize the request method. */
240244
enum htp_method_t request_method_number;
241245

246+
SCAN_BUILD_X64_PADDING(int pad2);
247+
242248
/**
243249
* Request URI, raw, as given to us on the request line. This field can take different forms,
244250
* for example authority for CONNECT methods, absolute URIs for proxy requests, and the query
@@ -421,6 +427,8 @@ struct htp_tx_t {
421427
*/
422428
int response_protocol_number;
423429

430+
SCAN_BUILD_X64_PADDING(int pad3);
431+
424432
/**
425433
* Response status code, as text. Starts as NULL and can remain NULL on
426434
* an invalid response that does not specify status code.
@@ -445,6 +453,8 @@ struct htp_tx_t {
445453
/** Have we seen the server respond with a 100 response? */
446454
int seen_100continue;
447455

456+
SCAN_BUILD_X64_PADDING(int pad4);
457+
448458
/** Parsed response headers. Contains instances of htp_header_t. */
449459
htp_table_t *response_headers;
450460

@@ -512,6 +522,8 @@ struct htp_tx_t {
512522
*/
513523
enum htp_content_encoding_t response_content_encoding_processing;
514524

525+
SCAN_BUILD_X64_PADDING(int pad5);
526+
515527
/**
516528
* This field will contain the response content type when that information
517529
* is available in response headers. The contents of the field will be converted

htp/htp_core.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,57 @@
4343
extern "C" {
4444
#endif
4545

46+
/* Define SCAN_BUILD_X64_PADDING to add padding to structs for
47+
* when clang scan-build is used with the optin.performance.Padding
48+
* checker. */
49+
#if defined(__clang_analyzer__)
50+
/** FreeBSD does not define __WORDSIZE, but it uses __LONG_BIT */
51+
#ifndef __WORDSIZE
52+
#ifdef __LONG_BIT
53+
#define __WORDSIZE __LONG_BIT
54+
#else
55+
#ifdef LONG_BIT
56+
#define __WORDSIZE LONG_BIT
57+
#endif
58+
#endif
59+
#endif
60+
61+
/** Windows does not define __WORDSIZE, but it uses __X86__ */
62+
#ifndef __WORDSIZE
63+
#if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
64+
#define __WORDSIZE 32
65+
#else
66+
#if defined(__X86_64__) || defined(_X86_64_) || \
67+
defined(__x86_64) || defined(__x86_64__) || \
68+
defined(__amd64) || defined(__amd64__)
69+
#define __WORDSIZE 64
70+
#endif
71+
#endif
72+
#endif
73+
74+
/** if not succesful yet try the data models */
75+
#ifndef __WORDSIZE
76+
#if defined(_ILP32) || defined(__ILP32__)
77+
#define __WORDSIZE 32
78+
#endif
79+
#if defined(_LP64) || defined(__LP64__)
80+
#define __WORDSIZE 64
81+
#endif
82+
#endif
83+
84+
#ifndef __WORDSIZE
85+
#define __WORDSIZE 64
86+
#endif
87+
88+
#if __WORDSIZE==64
89+
#define SCAN_BUILD_X64_PADDING(x) x
90+
#else
91+
#define SCAN_BUILD_X64_PADDING(_x)
92+
#endif
93+
#else /* else __clang_analyzer__ */
94+
#define SCAN_BUILD_X64_PADDING(_x)
95+
#endif /* end __clang_analyzer__ */
96+
4697
typedef int htp_status_t;
4798

4899
typedef struct htp_cfg_t htp_cfg_t;

0 commit comments

Comments
 (0)