diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,3 +7,7 @@
 ## 0.1.2.0 -- 2020-05-19
 
 * Support for Latex
+
+## 0.1.2.1 -- 2020-05-20
+
+* Fix overflow of parsing number
diff --git a/csrc/sixel.c b/csrc/sixel.c
--- a/csrc/sixel.c
+++ b/csrc/sixel.c
@@ -1,17 +1,31 @@
+#include <string.h>
+#include <stdio.h>
+
 int
 bufsize(int width,int height){
   return 256+((5+3*3+2+1)*width + 1)*height;
 }
 
 void putnum(unsigned char* buf,int* p, unsigned int r) {
-  int v100 = (r)/100;
-  int v10 = ((r)%100)/10;
-  int v1 = (r)%10;
-  if(v100)
-    buf[(*p)++] = '0' + v100;
-  if(v100 || v10)
-    buf[(*p)++] = '0' + v10;
-  buf[(*p)++] = '0' + v1;
+  if(r >= 1000) {
+    unsigned char sbuf[32];
+    int len;
+    int i;
+    sprintf(sbuf,"%d",r);
+    len=strlen(sbuf);
+    for(i=0;i<len;i++){
+      buf[(*p)++] = sbuf[i];
+    }
+  } else {
+    int v100 = (r)/100;
+    int v10 = ((r)%100)/10;
+    int v1 = (r)%10;
+    if(v100)
+      buf[(*p)++] = '0' + v100;
+    if(v100 || v10)
+      buf[(*p)++] = '0' + v10;
+    buf[(*p)++] = '0' + v1;
+  }
 }
 
 int
diff --git a/sixel.cabal b/sixel.cabal
--- a/sixel.cabal
+++ b/sixel.cabal
@@ -1,6 +1,6 @@
 cabal-version:       >=1.10
 name:                sixel
-version:             0.1.2.0
+version:             0.1.2.1
 synopsis:            Sixel library to show images in a terminal emulator
 description:         Sixel can show graphics on a terminal emulator. This library is developed to showing images on ghci.
 license:             BSD3
