X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_print.c;h=c7bd3a62fa87b1e3794890f93b8a4fb0c25b0404;hp=e5abd4de614533964c0b3c4e9d4b1a2e711f7c69;hb=6b43eaddcd1d9397fb3d51ce4c34f02472e93417;hpb=f9d358b4f3cf9b44727a0ee5c08f8ca6ae4e3821 diff --git a/ncurses/tinfo/lib_print.c b/ncurses/tinfo/lib_print.c index e5abd4de..c7bd3a62 100644 --- a/ncurses/tinfo/lib_print.c +++ b/ncurses/tinfo/lib_print.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2009 Free Software Foundation, Inc. * + * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -39,17 +39,21 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_print.c,v 1.19 2009/06/06 20:26:17 tom Exp $") +MODULE_ID("$Id: lib_print.c,v 1.20 2010/06/05 22:18:35 tom Exp $") NCURSES_EXPORT(int) NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len) /* ship binary character data to the printer via mc4/mc5/mc5p */ { + int result; char *mybuf, *switchon; - size_t onsize, offsize, res; + size_t onsize, offsize; + size_t need; errno = 0; - if (!HasTInfoTerminal(SP_PARM) || (!prtr_non && (!prtr_on || !prtr_off))) { + if (!HasTInfoTerminal(SP_PARM) + || len <= 0 + || (!prtr_non && (!prtr_on || !prtr_off))) { errno = ENODEV; return (ERR); } @@ -64,8 +68,10 @@ NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len) offsize = strlen(prtr_off); } + need = onsize + (size_t) len + offsize; + if (switchon == 0 - || (mybuf = typeMalloc(char, onsize + len + offsize + 1)) == 0) { + || (mybuf = typeMalloc(char, need + 1)) == 0) { errno = ENOMEM; return (ERR); } @@ -82,7 +88,7 @@ NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len) * data has actually been shipped to the terminal. If the write(2) * operation is truly atomic we're protected from this. */ - res = write(TerminalOf(SP_PARM)->Filedes, mybuf, onsize + len + offsize); + result = (int) write(TerminalOf(SP_PARM)->Filedes, mybuf, need); /* * By giving up our scheduler slot here we increase the odds that the @@ -93,7 +99,7 @@ NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len) (void) sleep(0); #endif free(mybuf); - return (res); + return (result); } #if NCURSES_SP_FUNCS && !defined(USE_TERM_DRIVER)