diff --git a/sql/protocol.cc b/sql/protocol.cc
index bf8faec006a845c8144e27b97ebc600d1591b2b5..ad667bd0ba6dcfa4e36621e3a39da53ba01dd02e 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -292,7 +292,10 @@ void net_send_error_packet(THD *thd, uint sql_errno, const char *err)
 {
   NET *net= &thd->net;
   uint length;
-  uchar buff[MYSQL_ERRMSG_SIZE+2], *pos;
+  /*
+    buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + MYSQL_ERRMSG_SIZE:512
+  */
+  uchar buff[2+1+SQLSTATE_LENGTH+MYSQL_ERRMSG_SIZE], *pos;
 
   DBUG_ENTER("send_error_packet");