#7419: Fix a crash on Windows in locale.setlocale() when the category
is outside the allowed range.
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 94d0014..f1f4abf 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -163,6 +163,14 @@
     if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
         return NULL;
 
+#if defined(MS_WINDOWS)
+    if (category < LC_MIN || category > LC_MAX)
+    {
+        PyErr_SetString(Error, "invalid locale category");
+        return NULL;
+    }
+#endif
+
     if (locale) {
         /* set locale */
         result = setlocale(category, locale);