Skip to content

Commit

Permalink
scan-build: work around optin.performance.Padding
Browse files Browse the repository at this point in the history
Since the layout has to be preserved, padding is added.
  • Loading branch information
victorjulien committed Dec 18, 2024
1 parent b28eadc commit 46b43fd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions htp/htp.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ struct htp_tx_t {
*/
int is_config_shared;

SCAN_BUILD_X64_PADDING(int pad0;)

/** The user data associated with this transaction. */
void *user_data;

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

SCAN_BUILD_X64_PADDING(int pad1;)

/** The first line of this request. */
bstr *request_line;

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

SCAN_BUILD_X64_PADDING(int pad2;)

/**
* Request URI, raw, as given to us on the request line. This field can take different forms,
* for example authority for CONNECT methods, absolute URIs for proxy requests, and the query
Expand Down Expand Up @@ -421,6 +427,8 @@ struct htp_tx_t {
*/
int response_protocol_number;

SCAN_BUILD_X64_PADDING(int pad3;)

/**
* Response status code, as text. Starts as NULL and can remain NULL on
* an invalid response that does not specify status code.
Expand All @@ -445,6 +453,8 @@ struct htp_tx_t {
/** Have we seen the server respond with a 100 response? */
int seen_100continue;

SCAN_BUILD_X64_PADDING(int pad4;)

/** Parsed response headers. Contains instances of htp_header_t. */
htp_table_t *response_headers;

Expand Down Expand Up @@ -512,6 +522,8 @@ struct htp_tx_t {
*/
enum htp_content_encoding_t response_content_encoding_processing;

SCAN_BUILD_X64_PADDING(int pad5;)

/**
* This field will contain the response content type when that information
* is available in response headers. The contents of the field will be converted
Expand Down
51 changes: 51 additions & 0 deletions htp/htp_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,57 @@
extern "C" {
#endif

/* Define SCAN_BUILD_X64_PADDING to add padding to structs for
* when clang scan-build is used with the optin.performance.Padding
* checker. */
#if defined(__clang_analyzer__)
/** FreeBSD does not define __WORDSIZE, but it uses __LONG_BIT */
#ifndef __WORDSIZE
#ifdef __LONG_BIT
#define __WORDSIZE __LONG_BIT
#else
#ifdef LONG_BIT
#define __WORDSIZE LONG_BIT
#endif
#endif
#endif

/** Windows does not define __WORDSIZE, but it uses __X86__ */
#ifndef __WORDSIZE
#if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
#define __WORDSIZE 32
#else
#if defined(__X86_64__) || defined(_X86_64_) || \
defined(__x86_64) || defined(__x86_64__) || \
defined(__amd64) || defined(__amd64__)
#define __WORDSIZE 64
#endif
#endif
#endif

/** if not succesful yet try the data models */
#ifndef __WORDSIZE
#if defined(_ILP32) || defined(__ILP32__)
#define __WORDSIZE 32
#endif
#if defined(_LP64) || defined(__LP64__)
#define __WORDSIZE 64
#endif
#endif

#ifndef __WORDSIZE
#define __WORDSIZE 64
#endif

#if __WORDSIZE==64
#define SCAN_BUILD_X64_PADDING(x) x
#else
#define SCAN_BUILD_X64_PADDING(_x)
#endif
#else /* else __clang_analyzer__ */
#define SCAN_BUILD_X64_PADDING(_x)
#endif /* end __clang_analyzer__ */

typedef int htp_status_t;

typedef struct htp_cfg_t htp_cfg_t;
Expand Down

0 comments on commit 46b43fd

Please sign in to comment.