pastebin - collaborative debugging tool
rovema.kpaste.net RSS


RDE: Fix hang in RDS code due to setlocale() abuse in multithreaded application
Posted by Anonymous on Fri 28th Apr 2023 13:11
raw | new post
view followups (newest first): RDE: Fix hang in RDS code due to setlocale() abuse in multithreaded application by Anonymous

  1. Submodule RDS contains modified content
  2. diff --git a/RDS/Rds/RdsLib/RdsReal.cpp b/RDS/Rds/RdsLib/RdsReal.cpp
  3. index c8f28b2..8c33b42 100755
  4. --- a/RDS/Rds/RdsLib/RdsReal.cpp
  5. +++ b/RDS/Rds/RdsLib/RdsReal.cpp
  6. @@ -44,6 +44,8 @@
  7.  #include "RdsClientLocal.h"
  8.  #include "DExtMath.hpp"
  9.  
  10. +#include <locale.h>
  11. +
  12.  
  13.  #define RINLINE
  14.  
  15. @@ -1539,10 +1541,24 @@ RINLINE T_Bool C_RdsUnit::readUnitSizeFile(const string &_path)
  16.  {
  17.    T_Bool isOK = true;
  18.  
  19. -  char savedLocale[32];
  20. -  /* Get the name of the current locale.  */
  21. -  strncpy(savedLocale, setlocale (LC_NUMERIC, NULL), 32);
  22. -  setlocale(LC_NUMERIC, "C");
  23. +  locale_t saved_locale;
  24. +  locale_t posix_locale;
  25. +  int saved_errno;
  26. +
  27. +  posix_locale = newlocale(LC_ALL_MASK, "POSIX", (locale_t)0);
  28. +  if (posix_locale == (locale_t)0) {
  29. +       saved_errno = errno;
  30. +       stringstream errorMsg(stringstream::out);
  31. +       errorMsg << "C_RdsUnit::readUnitSizeFile: newlocale(POSIX) failed with errno=" << saved_errno << ".\n";
  32. +       poSuRdsError->errorLog (errorMsg.str().c_str());
  33. +       return(false);
  34. +  }
  35. +
  36. +  /*
  37. +   * Use POSIX locale because the code below uses functions which
  38. +   * parse floating-poing values using locale-specific functions
  39. +   */
  40. +  saved_locale = uselocale(posix_locale);
  41.  
  42.    string completeFileName(SIZE_AND_UNIT_DIR);
  43.    if ( !_path.empty() )
  44. @@ -1617,7 +1633,10 @@ RINLINE T_Bool C_RdsUnit::readUnitSizeFile(const string &_path)
  45.      poSuRdsError->perrorLog (errorMsg.str().c_str());
  46.      isOK = false;
  47.    } // end else !inStream
  48. -  setlocale(LC_NUMERIC, savedLocale);
  49. +  
  50. +  (void)uselocale(saved_locale);
  51. +  freelocale(posix_locale);
  52. +
  53.    return(isOK);
  54.  } // end of method C_RdsUnit::readUnitSizeFile

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at