diff --git a/autoconf-win32/config.h b/autoconf-win32/config.h
--- a/autoconf-win32/config.h
+++ b/autoconf-win32/config.h
@@ -293,13 +293,17 @@
 /* Define to 1 when using POSIX threads (pthreads). */
 /* #undef MYTHREAD_POSIX */
 
+#ifdef _WIN64
 /* Define to 1 when using Windows Vista compatible threads. This uses features
    that are not available on Windows XP. */
-#define MYTHREAD_VISTA 1
-
+# define MYTHREAD_VISTA 1
+#else
 /* Define to 1 when using Windows 95 (and thus XP) compatible threads. This
-   avoids use of features that were added in Windows Vista. */
-/* #undef MYTHREAD_WIN95 */
+   avoids use of features that were added in Windows Vista.
+   This is used for 32-bit x86 builds for compatibility reasons since it
+   makes no measurable difference in performance compared to Vista threads. */
+# define MYTHREAD_WIN95 1
+#endif
 
 /* Define to 1 to disable debugging code. */
 #define NDEBUG 1
diff --git a/lzma-clib.cabal b/lzma-clib.cabal
--- a/lzma-clib.cabal
+++ b/lzma-clib.cabal
@@ -1,5 +1,5 @@
 name:                lzma-clib
-version:             5.2.1
+version:             5.2.2
 license:             PublicDomain
 license-file:        LICENSE
 author:              Lasse Collin
@@ -15,7 +15,7 @@
    by LZMA\/XZ bindings such as </package/lzma lzma>.
    .
    The @liblzma@ code contained in this package version has been
-   extracted from the <http://tukaani.org/xz/ XZ Utils> 5.2.1 release.
+   extracted from the <http://tukaani.org/xz/ XZ Utils> 5.2.2 release.
    .
    NOTE: This package is only buildable on Windows.
 
@@ -39,6 +39,10 @@
   src/liblzma/rangecoder/*.h
   src/liblzma/simple/*.c
   src/liblzma/simple/*.h
+
+source-repository head
+  type:     git
+  location: https://github.com/hvr/lzma-clib.git
 
 library
   default-language:    Haskell2010
diff --git a/src/common/tuklib_physmem.c b/src/common/tuklib_physmem.c
--- a/src/common/tuklib_physmem.c
+++ b/src/common/tuklib_physmem.c
@@ -37,7 +37,10 @@
 #	define __USE_INLINE__
 #	include <proto/exec.h>
 
-// AIX
+#elif defined(__QNX__)
+#	include <sys/syspage.h>
+#	include <string.h>
+
 #elif defined(TUKLIB_PHYSMEM_AIX)
 #	include <sys/systemcfg.h>
 
@@ -125,6 +128,15 @@
 
 #elif defined(AMIGA) || defined(__AROS__)
 	ret = AvailMem(MEMF_TOTAL);
+
+#elif defined(__QNX__)
+	const struct asinfo_entry *entries = SYSPAGE_ENTRY(asinfo);
+	size_t count = SYSPAGE_ENTRY_SIZE(asinfo) / sizeof(struct asinfo_entry);
+	const char *strings = SYSPAGE_ENTRY(strings)->data;
+
+	for (size_t i = 0; i < count; ++i)
+		if (strcmp(strings + entries[i].name, "ram") == 0)
+			ret += entries[i].end - entries[i].start + 1;
 
 #elif defined(TUKLIB_PHYSMEM_AIX)
 	ret = _system_configuration.physmem;
diff --git a/src/liblzma/api/lzma.h b/src/liblzma/api/lzma.h
--- a/src/liblzma/api/lzma.h
+++ b/src/liblzma/api/lzma.h
@@ -82,12 +82,20 @@
 #	if !defined(UINT32_C) || !defined(UINT64_C) \
 			|| !defined(UINT32_MAX) || !defined(UINT64_MAX)
 		/*
-		 * MSVC has no C99 support, and thus it cannot be used to
-		 * compile liblzma. The liblzma API has to still be usable
-		 * from MSVC, so we need to define the required standard
-		 * integer types here.
+		 * MSVC versions older than 2013 have no C99 support, and
+		 * thus they cannot be used to compile liblzma. Using an
+		 * existing liblzma.dll with old MSVC can work though(*),
+		 * but we need to define the required standard integer
+		 * types here in a MSVC-specific way.
+		 *
+		 * (*) If you do this, the existing liblzma.dll probably uses
+		 *     a different runtime library than your MSVC-built
+		 *     application. Mixing runtimes is generally bad, but
+		 *     in this case it should work as long as you avoid
+		 *     the few rarely-needed liblzma functions that allocate
+		 *     memory and expect the caller to free it using free().
 		 */
-#		if defined(_WIN32) && defined(_MSC_VER)
+#		if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800
 			typedef unsigned __int8 uint8_t;
 			typedef unsigned __int32 uint32_t;
 			typedef unsigned __int64 uint64_t;
diff --git a/src/liblzma/api/lzma/version.h b/src/liblzma/api/lzma/version.h
--- a/src/liblzma/api/lzma/version.h
+++ b/src/liblzma/api/lzma/version.h
@@ -22,7 +22,7 @@
  */
 #define LZMA_VERSION_MAJOR 5
 #define LZMA_VERSION_MINOR 2
-#define LZMA_VERSION_PATCH 1
+#define LZMA_VERSION_PATCH 2
 #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
 
 #ifndef LZMA_VERSION_COMMIT
diff --git a/src/liblzma/common/index.c b/src/liblzma/common/index.c
--- a/src/liblzma/common/index.c
+++ b/src/liblzma/common/index.c
@@ -339,7 +339,7 @@
 /// Allocate and initialize a new Stream using the given base offsets.
 static index_stream *
 index_stream_init(lzma_vli compressed_base, lzma_vli uncompressed_base,
-		lzma_vli stream_number, lzma_vli block_number_base,
+		uint32_t stream_number, lzma_vli block_number_base,
 		const lzma_allocator *allocator)
 {
 	index_stream *s = lzma_alloc(sizeof(index_stream), allocator);
@@ -1008,6 +1008,8 @@
 		iter->internal[ITER_GROUP].p = NULL;
 	}
 
+	// NOTE: lzma_index_iter.stream.number is lzma_vli but we use uint32_t
+	// internally.
 	iter->stream.number = stream->number;
 	iter->stream.block_count = stream->record_count;
 	iter->stream.compressed_offset = stream->node.compressed_base;
diff --git a/src/liblzma/lz/lz_encoder.c b/src/liblzma/lz/lz_encoder.c
--- a/src/liblzma/lz/lz_encoder.c
+++ b/src/liblzma/lz/lz_encoder.c
@@ -139,7 +139,7 @@
 			&& coder->mf.read_pos < coder->mf.read_limit) {
 		// Match finder may update coder->pending and expects it to
 		// start from zero, so use a temporary variable.
-		const size_t pending = coder->mf.pending;
+		const uint32_t pending = coder->mf.pending;
 		coder->mf.pending = 0;
 
 		// Rewind read_pos so that the match finder can hash
diff --git a/src/liblzma/lzma/lzma_encoder.c b/src/liblzma/lzma/lzma_encoder.c
--- a/src/liblzma/lzma/lzma_encoder.c
+++ b/src/liblzma/lzma/lzma_encoder.c
@@ -464,7 +464,7 @@
 	bittree_reset(lencoder->high, LEN_HIGH_BITS);
 
 	if (!fast_mode)
-		for (size_t pos_state = 0; pos_state < num_pos_states;
+		for (uint32_t pos_state = 0; pos_state < num_pos_states;
 				++pos_state)
 			length_update_prices(lencoder, pos_state);
 
