mercredi 23 juin 2021

C++ std::regex_search crash on linux

I made a program running c++ and it worked well. I tried turning it into library, for windows i used visual studio and created dll, works perfectly. For linux i used cmake, this cmake :

cmake_minimum_required(VERSION 3.0.0)

project(parser)
set(CMAKE_BUILD_TYPE Release)
find_package(JNI REQUIRED)
set(CURL_LIBRARY "-lcurl") 
find_package(CURL REQUIRED)
include_directories(${JNI_INCLUDE_DIRS} ${CURL_INCLUDE_DIR})
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES 
    parser.cpp
    parser_Podaci.cpp
    podaci.cpp
)
add_library(parser SHARED ${SOURCE_FILES})
target_link_libraries(parser ${CURL_LIBRARIES})
include(CPack)

And it crashes on a specific line:

std::smatch m; 
std::string readBuffer;//this is argument in a function
std::regex regexp5("\"timestamp\":\\[([0-9,]+)\\]");
std::regex_search(readBuffer, m, regexp5);
std::vector<std::string> tm = podeli(m.str(1));
std::regex regexp6("\"close\":\\[([0-9,.nul]+)\\]");

std::regex_search(readBuffer, m, regexp6); // <- this is where it crashes
     
std::vector<std::string> cl = podeli(m.str(1)); //this function splits string into vector

The apsurdity of things is, this is 6th regex that searches same file in same order as last 5 but instead of close, one searches for open, high, low and etc. The finish well while this one crashes for no reason. I searched forum for answer, there are similiar questions but with no answer to solve my problem. I tried putting it in try catch block and searching for error that way but it just crashes silently. I assume its segmentation failed, core dumped. But i couldn't check, as im running this library on java program.

I read it has something to do with partial compilation, but im not sure how to solve this

NOTE: This is not only library in program, i used few, all others are working very well. Only this one crashes on a specific line.

Aucun commentaire:

Enregistrer un commentaire