Skip to content

Commit

Permalink
funopen: bug fix and little optimisation to the cookie fgets loop
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhams committed Aug 15, 2020
1 parent 868fedf commit ccf574a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libdicl/configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ(2.65)
AC_INIT([libdicl],
[0.1.29],
[0.1.30],
[[email protected]])

AC_SUBST(ACLOCAL_AMFLAGS, "-I macros")
Expand Down
13 changes: 7 additions & 6 deletions libdicl/src/libdicl/funopen_replacements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ static optional<internal_file_ptr_entry> find_remove_entry_for_key( size_t key )
auto finder = internal_cookie_map.find( key );
if( finder != internal_cookie_map.end() )
{
internal_cookie_map.erase(finder);
return { finder->second };
// Keep a copy of the value from the iterator to ensure correct lifetime.
internal_file_ptr_entry retval = finder->second;
internal_cookie_map.erase(finder);
return { retval };
}
else
{
Expand Down Expand Up @@ -265,17 +267,16 @@ char * ld_fgets( char *s, int size, FILE *stream )
size_t max = size - 1;
char *cur = s;
size_t numread = 0;
char tmpplace[1];
do {
size_t loopread = entry.cookie_funcs.readfn( entry.cookie_funcs.cookie,
tmpplace, 1 );
cur, 1 );
if(loopread==0) {
break;
}
*cur = tmpplace[0];
char val = *cur;
cur++;
numread++;
if( tmpplace[0] == '\n' ) {
if( val == '\n' ) {
break;
}
}
Expand Down

0 comments on commit ccf574a

Please sign in to comment.