help-libidn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: libidn 1.29 static lib / msvc12 c++ / windows & 64bit issues


From: Tom Clunie
Subject: Fwd: libidn 1.29 static lib / msvc12 c++ / windows & 64bit issues
Date: Tue, 11 Nov 2014 18:03:52 -0500

Sorry, I probably should have sent it here as well.  Thanks!  -Tom

---------- Forwarded message ----------
From: Tom Clunie <address@hidden>
Date: Mon, Nov 10, 2014 at 10:12 PM
Subject: libidn 1.29 static lib / msvc12 c++ / windows & 64bit issues
To: address@hidden


Hi, I encountered two issues using the above.

1- Unable to link to a static library of libidn unless I define IDNAPI prior to idna.h.  The lib was built using the provided MSVC solution file in the /windows directory.  If IDNAPI is not defined as below, I get linker errors even after I reference the static lib.  I'm guessing this is a decoration issue.
Example:
MyFile.cpp
#define IDNAPI   // if I remove this line, i get linker errors
#include <idna.h>

2 - 64bit size_t / glong assignment error causing failure

Calling idna_to_ascii_8z with any UTF-8 input leads to an error.  I tracked it down to the use of size_t ucs4len in stringprep.c (374) as it gets passed down to nfkc.c and assigned at line 457.  The assigned value (64 bit uint) is casted to glong (32bit signed int) and assigned a value, which is then discarded, leaving the 64bit uint in an undefined state.  This causes a malloc failure later on back up the call stack.  This only happens on 64 bit builds, 32 bit builds work fine, most likely due to size_t being a 32bit int vs a 64 bit int, hiding the casting errors.

For a quick fix to get past the 32/64 bit issue, I redefined 'glong' from 'long' to 'long long' in nfkc.c line 43.  Longer term, it might make more sense to redefine the 'items_written' parameter to an unsigned int * (size_t?) rather than a long *, as I dont think items_written would ever be negative (?).  Plus eliminate these casting/platform issues.

Source cpp to recreate:
#include <string>
#include <codecvt>
#define IDNA_ACE_PREFIX
#define IDNAPI // must be included for successful link
#include <idna.h>

int main()
{
std::wstring ws = L"¢¢¢.com";  // unicode test domain
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
char* buf = nullptr;
// 64 bit:  triggers msvc breakpoint due to error.  32 bit:  works fine
auto r = idna_to_ascii_8z( conv.to_bytes( ws ).c_str(), &buf, 0 );
}

Lastly, a windows project for libidn2 would be nice :)  Thanks!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]