Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build failures on MinGW during package CI #1452

Merged
merged 13 commits into from
Jun 21, 2024
7 changes: 0 additions & 7 deletions 3rdParty/LightPcapNg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ add_library(

target_compile_definitions(light_pcapng PUBLIC -DUNIVERSAL)

# FIXME: https://github.com/seladb/PcapPlusPlus/issues/1347
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wincompatible-pointer-types HAVE_W_INCOMPATIBLE_POINTER_TYPES)
if(HAVE_W_INCOMPATIBLE_POINTER_TYPES)
target_compile_options(light_pcapng PRIVATE -Wno-incompatible-pointer-types)
endif()

if(BUILD_SHARED_LIBS)
set_property(TARGET light_pcapng PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
Expand Down
5 changes: 1 addition & 4 deletions 3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
#include <assert.h>

struct _light_pcapng_stream {
union {
FILE* fd;
void *reserved;
} stream;
struct light_file_t *file; // PCPP patch
struct _light_pcapng *current_block;
int valid;
};
Expand Down
14 changes: 8 additions & 6 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ int light_pcapng_to_compressed_file(const char *file_name, const light_pcapng pc
light_pcapng_stream light_open_stream(const char *file_name)
{
light_pcapng_stream pcapng = calloc(1, sizeof(struct _light_pcapng_stream));
pcapng->stream.fd = light_open(file_name, LIGHT_OREAD);
pcapng->file = light_open(file_name, LIGHT_OREAD); // PCPP patch

if (pcapng->stream.fd == NULL) {
if (pcapng->file == NULL) { // PCPP patch
free(pcapng);
return NULL;
}
Expand All @@ -114,8 +114,9 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng)
pcapng->current_block = NULL;
}

if (light_read(pcapng->stream.fd, &block_type, sizeof(block_type)) == -1 ||
light_read(pcapng->stream.fd, &block_total_length, sizeof(block_total_length)) == -1) {
// PCPP patch
if (light_read(pcapng->file, &block_type, sizeof(block_type)) == -1 ||
light_read(pcapng->file, &block_total_length, sizeof(block_total_length)) == -1) {
pcapng->valid = 0;
return NULL;
}
Expand All @@ -129,7 +130,8 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng)
block_data[0] = block_type;
block_data[1] = block_total_length;

if (light_read(pcapng->stream.fd, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == -1) {
// PCPP patch
if (light_read(pcapng->file, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == -1) {
free(block_data);
pcapng->valid = 0;
return NULL;
Expand All @@ -152,7 +154,7 @@ int light_close_stream(light_pcapng_stream pcapng)
pcapng->current_block = NULL;
}

light_close(pcapng->stream.fd);
light_close(pcapng->file); // PCPP patch
pcapng->valid = 0;
free(pcapng);

Expand Down
3 changes: 3 additions & 0 deletions Packet++/src/Asn1Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,10 @@ namespace pcpp
std::vector<uint8_t> Asn1IntegerRecord::encodeValue() const
{
std::vector<uint8_t> result;

#if !(defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW32_MAJOR_VERSION))
result.reserve(m_ValueLength);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why the compiler complains here, but I think it's fine to remove it:
https://github.com/seladb/PcapPlusPlus/actions/runs/9562329238/job/26358481698

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we ignore this line only for MinGW?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a compilation error so not sure we can ignore it, but I think removing it is ok, I don't foresee a big performance impact because of it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean ifndef MinGW or some similar syntax.
I think it's better to keep the reserve as it still works for other platforms.

Copy link
Owner Author

@seladb seladb Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with __MIGW32__ / __MINGW64__, but it didn't work: https://github.com/seladb/PcapPlusPlus/actions/runs/9593015503/job/26452660814

Then I changed to __MINGW32_VERSION_MAJOR / __MINGW64_VERSION_MAJOR as we do here and it worked: https://github.com/seladb/PcapPlusPlus/actions/runs/9593255865

#endif

switch (m_ValueLength)
{
Expand Down
Loading