From 1d2dea0207b8f97a2060c3f18825628813bde09b Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Sat, 3 Aug 2013 17:13:43 +0200 Subject: [PATCH] fix #4: segfault when no encoding detected caused by trying to wrap 0 as a Python string --- src/cchardet/_cchardet.pyx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cchardet/_cchardet.pyx b/src/cchardet/_cchardet.pyx index 46285ea..3dfc995 100644 --- a/src/cchardet/_cchardet.pyx +++ b/src/cchardet/_cchardet.pyx @@ -30,7 +30,8 @@ def detect(char *msg): ret = csd_close(csd) elif result == 0: # Detected early ret = csd_close(csd) - return ret + if ret: + return ret def detect_with_confidence(char *msg): cdef csd_t csd = csd_open() @@ -45,5 +46,7 @@ def detect_with_confidence(char *msg): detected_charset = csd_close2(csd, &confidence) else: # Error, signal with a negative number raise Exception("Error, signal with a negative number") - return detected_charset,confidence - + if detected_charset: + return detected_charset, confidence + else: + return None, None