Skip to content

Commit

Permalink
Fix overflow in jump_percent calculation.
Browse files Browse the repository at this point in the history
Don't send "ti" after lsystem until user has pressed a key.
  • Loading branch information
gwsw committed Jan 25, 1996
1 parent ebd2a12 commit 1243358
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 46 deletions.
16 changes: 8 additions & 8 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ less: ${OBJ}
lesskey: lesskey.${O} version.${O}
${CC} ${LDFLAGS} -o $@ lesskey.${O} version.${O}

${OBJ}: less.h defines.h funcs.h
${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h

filename.${O}: filename.c
filename.${O}: ${srcdir}/filename.c
${CC} -c -DHELPFILE=\"${datadir}/less.hlp\" -I. ${CPPFLAGS} ${CFLAGS} ${srcdir}/filename.c

install: all ${srcdir}/less.hlp ${srcdir}/less.nro ${srcdir}/lesskey.nro installdirs
Expand Down Expand Up @@ -104,14 +104,13 @@ defines.h: stamp-h
stamp-h: defines.h.in config.status
test ! -f stamp-h || CONFIG_FILES= CONFIG_HEADERS=defines.h ./config.status
touch stamp-h
Makefile: Makefile.in config.status
Makefile: ${srcdir}/Makefile.in config.status
CONFIG_FILES=Makefile CONFIG_HEADERS= ./config.status
config.status: ${srcdir}/configure
./config.status --recheck

configure: configure.in
autoheader
autoconf
${srcdir}/configure: ${srcdir}/configure.in
cd ${srcdir}; autoheader; autoconf

lint:
lint -I. ${CPPFLAGS} ${SRC}
Expand Down Expand Up @@ -151,8 +150,9 @@ ${srcdir}/lesskey.man: ${srcdir}/lesskey.nro


dist: ${DISTFILES}
if [ ! -d release ]; then mkdir release; fi
@REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/less-\1/' -e q ${srcdir}/version.c`; \
if [ ! -d ${srcdir}/release ]; then mkdir ${srcdir}/release; fi
@cd ${srcdir}; \
REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/less-\1/' -e q version.c`; \
rm -rf release/$$REL; mkdir release/$$REL; \
echo "Creating release/$$REL/$$REL.tar.gz"; \
rm -rf $$REL; mkdir $$REL; \
Expand Down
7 changes: 3 additions & 4 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,9 @@ exec_mca()
}

if (shellcmd == NULL)
lsystem("");
lsystem("", "!done");
else
lsystem(shellcmd);
error("!done", NULL_PARG);
lsystem(shellcmd, "!done");
break;
#endif
#if PIPEC
Expand Down Expand Up @@ -1108,7 +1107,7 @@ commands()
* and pass it to the system to execute.
*/
cmd_exec();
lsystem(pr_expand(editproto, 0));
lsystem(pr_expand(editproto, 0), (char*)NULL);
/*
* Re-edit the file, since data may have changed.
* Some editors even recreate the file, so flushing
Expand Down
4 changes: 1 addition & 3 deletions help.c.old
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ help(nomsg)
#endif
#endif
free(helpfile);
lsystem(cmd);
if (!nomsg)
error("End of help", NULL_PARG);
lsystem(cmd, nomsg ? (char*)NULL : "End of help");
free(cmd);
#endif
}
5 changes: 1 addition & 4 deletions jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ jump_percent(percent)
error("Don't know length of file", NULL_PARG);
return;
}
/*
* {{ This calculation may overflow! }}
*/
pos = (percent * len) / 100;
pos = percent_pos(len, percent);
if (pos >= len)
pos = len-1;

Expand Down
9 changes: 8 additions & 1 deletion lsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ extern IFILE curr_ifile;
* Like plain "system()", but handles resetting terminal modes, etc.
*/
public void
lsystem(cmd)
lsystem(cmd, donemsg)
char *cmd;
char *donemsg;
{
register int inp;
register char *shell;
Expand Down Expand Up @@ -145,6 +146,12 @@ lsystem(cmd)

init_signals(1);
raw_mode(1);
if (donemsg != NULL)
{
putstr(donemsg);
putstr(" (press RETURN)");
get_return();
}
init();
screen_trashed = 1;

Expand Down
45 changes: 30 additions & 15 deletions os.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#if HAVE_VALUES_H
#include <values.h>
#endif
#if HAVE_LIMITS_H
#include <limits.h>
#endif

#if HAVE_TIME_T
#define time_type time_t
Expand Down Expand Up @@ -192,16 +195,15 @@ errno_message(filename)
/*
* Return the largest possible number that can fit in a long.
*/
#ifdef MAXLONG
static long
get_maxlong()
{
#ifdef LONG_MAX
return (LONG_MAX);
#else
#ifdef MAXLONG
return (MAXLONG);
}
#else
static long
get_maxlong()
{
long n, n2;

/*
Expand All @@ -216,22 +218,35 @@ get_maxlong()
n2 *= 2;
} while (n2 / 2 == n);
return (n);
}
#endif
#endif
}

/*
* Return the ratio of two longs, as a percentage.
* Return the ratio of two POSITIONS, as a percentage.
* {{ Assumes a POSITION is a long int. }}
*/
public int
percentage(num, den)
long num, den;
POSITION num, den;
{
if (num <= get_maxlong() / 100)
return ((100 * num) / den);
else
return (num / (den / 100));
}

/*
* Return the specified percentage of a POSITION.
* {{ Assumes a POSITION is a long int. }}
*/
public POSITION
percent_pos(pos, percent)
POSITION pos;
int percent;
{
static long maxlong100 = 0;

if (maxlong100 == 0)
maxlong100 = get_maxlong() / 100;
if (num > maxlong100)
return (num / (den/100));
if (pos <= get_maxlong() / 100)
return ((percent * pos) / 100);
else
return (100*num / den);
return (percent * (pos / 100));
}
30 changes: 21 additions & 9 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,26 @@ iprintf(fmt, parg)
return (col);
}

/*
* Get a RETURN.
* If some other non-trivial char is pressed, unget it, so it will
* become the next command.
*/
public void
get_return()
{
int c;

#if ONLY_RETURN
while ((c = getchr()) != '\n' && c != '\r')
bell();
#else
c = getchr();
if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR)
ungetcc(c);
#endif
}

/*
* Output a message in the lower left corner of the screen
* and wait for carriage return.
Expand All @@ -268,7 +288,6 @@ error(fmt, parg)
char *fmt;
PARG *parg;
{
int c;
int col = 0;
static char return_to_continue[] = " (press RETURN)";

Expand All @@ -293,14 +312,7 @@ error(fmt, parg)
so_exit();
col += sizeof(return_to_continue) + so_e_width;

#if ONLY_RETURN
while ((c = getchr()) != '\n' && c != '\r')
bell();
#else
c = getchr();
if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR)
ungetcc(c);
#endif
get_return();
lower_left();

if (col >= sc_width)
Expand Down
5 changes: 3 additions & 2 deletions version.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ v297 1/24/96 Don't call termcap if tgetent fails;
add #defines for buffers.
v298 1/24/96 Change @@ to ^K.
Add alternate search modifiers ^N, ^F, ^E.
v299 1/25/96 Fix percent overflow in jump_percent (thanks to Brent Wiese);
don't send "ti" after shell command till RETURN pressed.
*/

char version[] = "298";
char version[] = "299";

0 comments on commit 1243358

Please sign in to comment.