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

find() is pretty broken #1

Open
zpostfacto opened this issue Jun 15, 2017 · 0 comments
Open

find() is pretty broken #1

zpostfacto opened this issue Jun 15, 2017 · 0 comments

Comments

@zpostfacto
Copy link

zpostfacto commented Jun 15, 2017

ujson::find() is simply a wrapper around std::lower_bound, so it will almost always claim to find the key you are looking for, unless you pass a name that is less than all other keys.

Sorry for not submitting an official pull request, but the fix is pretty obvious. You need to do something like this:

inline object::const_iterator find(object const &obj, char const *name) {
    assert(std::is_sorted(obj.begin(), obj.end()));
    object::const_iterator it = std::lower_bound(obj.begin(), obj.end(), name,
                            [](name_value_pair const &lhs, char const *rhs) {
        return lhs.first < rhs;
    });
	if ( it == obj.end() || it->first != name )
		return obj.end();
	return it;
}
penberg added a commit to penberg/ujson that referenced this issue May 17, 2020
When building on Fedora Linux 30, ujson_test link fails with the
following error:

  /usr/bin/ld: CMakeFiles/ujson_test.dir/test.cpp.o: in function `std::thread::thread<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<____C_A_T_C_H____T_E_S_T____836()::{lambda()awangk#1}> >, void>::_Async_state_impl(std::tuple<____C_A_T_C_H____T_E_S_T____836()::{lambda()awangk#1}>&&)::{lambda()awangk#1}, , void>(std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<____C_A_T_C_H____T_E_S_T____836()::{lambda()awangk#1}> >, void>::_Async_state_impl(std::tuple<____C_A_T_C_H____T_E_S_T____836()::{lambda()awangk#1}>&&)::{lambda()awangk#1}&&)':
test.cpp:(.text+0x1b51f): undefined reference to `pthread_create'
  collect2: error: ld returned 1 exit status

Let's add the CMake's threads library (which maps to "-lpthread") to
ujson_test to fix linking on Linux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant