Fix a passel of ancient bugs in to_char(), including two distinct buffer overruns (neither of which seem likely to be exploitable as security holes, fortunately, since the provoker can't control the data written).  One of these is due to choosing to stomp on the output of a called function, which is bad news in any case; make it treat the called functions' results as read-only.  Avoid some unnecessary palloc/pfree traffic too; it's not really helpful to free small temporary objects, and again this is presuming more than it ought to about the nature of the results of called functions. Per report from Patrick Welche and additional code-reading by Imad.
Fix a passel of ancient bugs in to_char(), including two distinct buffer
overruns (neither of which seem likely to be exploitable as security holes,
fortunately, since the provoker can't control the data written).  One of
these is due to choosing to stomp on the output of a called function, which
is bad news in any case; make it treat the called functions' results as
read-only.  Avoid some unnecessary palloc/pfree traffic too; it's not
really helpful to free small temporary objects, and again this is presuming
more than it ought to about the nature of the results of called functions.
Per report from Patrick Welche and additional code-reading by Imad.

edespino/gpdb,oberstet/postgres-xl,Quikling/gpdb,yuanzhao/gpdb,Chibin/gpdb,xuegang/gpdb,Postgres-XL/Postgres-XL,janebeckman/gpdb,ahachete/gpdb,royc1/gpdb,techdragon/Postgres-XL,lintzc/gpdb,lintzc/gpdb,royc1/gpdb,xuegang/gpdb,zaksoup/gpdb,cjcjameson/gpdb,CraigHarris/gpdb,xinzweb/gpdb,rvs/gpdb,rvs/gpdb,cjcjameson/gpdb,greenplum-db/gpdb,50wu/gpdb,ashwinstar/gpdb,0x0FFF/gpdb,pavanvd/postgres-xl,ahachete/gpdb,zaksoup/gpdb,adam8157/gpdb,xinzweb/gpdb,greenplum-db/gpdb,lisakowen/gpdb,janebeckman/gpdb,CraigHarris/gpdb,janebeckman/gpdb,kmjungersen/PostgresXL,Chibin/gpdb,arcivanov/postgres-xl,edespino/gpdb,kaknikhil/gpdb,xinzweb/gpdb,Quikling/gpdb,zaksoup/gpdb,Postgres-XL/Postgres-XL,postmind-net/postgres-xl,royc1/gpdb,janebeckman/gpdb,edespino/gpdb,pavanvd/postgres-xl,Quikling/gpdb,xinzweb/gpdb,Quikling/gpdb,kaknikhil/gpdb,chrishajas/gpdb,rvs/gpdb,Chibin/gpdb,jmcatamney/gpdb,snaga/postgres-xl,lintzc/gpdb,CraigHarris/gpdb,CraigHarris/gpdb,ovr/postgres-xl,greenplum-db/gpdb,chrishajas/gpdb,kmjungersen/PostgresXL,pavanvd/postgres-xl,tpostgres-projects/tPostgres,Chibin/gpdb,greenplum-db/gpdb,adam8157/gpdb,royc1/gpdb,xuegang/gpdb,janebeckman/gpdb,rvs/gpdb,jmcatamney/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,0x0FFF/gpdb,yuanzhao/gpdb,lisakowen/gpdb,rvs/gpdb,ahachete/gpdb,techdragon/Postgres-XL,arcivanov/postgres-xl,Chibin/gpdb,xinzweb/gpdb,jmcatamney/gpdb,arcivanov/postgres-xl,ashwinstar/gpdb,ovr/postgres-xl,techdragon/Postgres-XL,Quikling/gpdb,lintzc/gpdb,pavanvd/postgres-xl,zaksoup/gpdb,lisakowen/gpdb,50wu/gpdb,kaknikhil/gpdb,lisakowen/gpdb,Quikling/gpdb,kmjungersen/PostgresXL,techdragon/Postgres-XL,rvs/gpdb,tpostgres-projects/tPostgres,0x0FFF/gpdb,zaksoup/gpdb,arcivanov/postgres-xl,ahachete/gpdb,techdragon/Postgres-XL,CraigHarris/gpdb,janebeckman/gpdb,kaknikhil/gpdb,edespino/gpdb,Quikling/gpdb,50wu/gpdb,ashwinstar/gpdb,postmind-net/postgres-xl,ovr/postgres-xl,lintzc/gpdb,CraigHarris/gpdb,yazun/postgres-xl,50wu/gpdb,rvs/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,kmjungersen/PostgresXL,edespino/gpdb,Quikling/gpdb,edespino/gpdb,ashwinstar/gpdb,adam8157/gpdb,50wu/gpdb,Postgres-XL/Postgres-XL,zaksoup/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,xuegang/gpdb,janebeckman/gpdb,edespino/gpdb,cjcjameson/gpdb,kaknikhil/gpdb,zeroae/postgres-xl,yuanzhao/gpdb,CraigHarris/gpdb,CraigHarris/gpdb,Quikling/gpdb,cjcjameson/gpdb,chrishajas/gpdb,yazun/postgres-xl,0x0FFF/gpdb,lisakowen/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,adam8157/gpdb,royc1/gpdb,ahachete/gpdb,kmjungersen/PostgresXL,pavanvd/postgres-xl,kaknikhil/gpdb,xuegang/gpdb,kaknikhil/gpdb,ahachete/gpdb,rvs/gpdb,snaga/postgres-xl,adam8157/gpdb,zeroae/postgres-xl,0x0FFF/gpdb,zeroae/postgres-xl,chrishajas/gpdb,kaknikhil/gpdb,50wu/gpdb,ashwinstar/gpdb,tpostgres-projects/tPostgres,CraigHarris/gpdb,lintzc/gpdb,jmcatamney/gpdb,royc1/gpdb,lisakowen/gpdb,xinzweb/gpdb,postmind-net/postgres-xl,janebeckman/gpdb,chrishajas/gpdb,ashwinstar/gpdb,50wu/gpdb,lisakowen/gpdb,ahachete/gpdb,royc1/gpdb,rvs/gpdb,greenplum-db/gpdb,edespino/gpdb,cjcjameson/gpdb,oberstet/postgres-xl,tpostgres-projects/tPostgres,janebeckman/gpdb,postmind-net/postgres-xl,yazun/postgres-xl,janebeckman/gpdb,cjcjameson/gpdb,yuanzhao/gpdb,Postgres-XL/Postgres-XL,kaknikhil/gpdb,greenplum-db/gpdb,oberstet/postgres-xl,kaknikhil/gpdb,yazun/postgres-xl,adam8157/gpdb,postmind-net/postgres-xl,Chibin/gpdb,jmcatamney/gpdb,royc1/gpdb,oberstet/postgres-xl,Chibin/gpdb,jmcatamney/gpdb,adam8157/gpdb,zeroae/postgres-xl,yuanzhao/gpdb,0x0FFF/gpdb,yazun/postgres-xl,ovr/postgres-xl,zaksoup/gpdb,arcivanov/postgres-xl,chrishajas/gpdb,jmcatamney/gpdb,lisakowen/gpdb,chrishajas/gpdb,adam8157/gpdb,lintzc/gpdb,Chibin/gpdb,0x0FFF/gpdb,cjcjameson/gpdb,xinzweb/gpdb,arcivanov/postgres-xl,Chibin/gpdb,ovr/postgres-xl,jmcatamney/gpdb,xuegang/gpdb,xuegang/gpdb,tpostgres-projects/tPostgres,Chibin/gpdb,snaga/postgres-xl,lintzc/gpdb,xuegang/gpdb,Postgres-XL/Postgres-XL,edespino/gpdb,snaga/postgres-xl,xuegang/gpdb,zeroae/postgres-xl,zaksoup/gpdb,chrishajas/gpdb,rvs/gpdb,greenplum-db/gpdb,oberstet/postgres-xl,50wu/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,ahachete/gpdb,Quikling/gpdb,ashwinstar/gpdb,snaga/postgres-xl,0x0FFF/gpdb,xinzweb/gpdb,edespino/gpdb,lintzc/gpdb