Properly check for miliseconds during screen update

This removes undefined behavior in the previous code by properly
checking for miliseconds (actually typing proper names, not abusing
pointer arithmetics).
This commit is contained in:
Konrad Borowski 2014-05-01 11:00:13 +02:00
parent dd47da92f5
commit 77bc4c5725
2 changed files with 12 additions and 16 deletions

View file

@ -396,6 +396,11 @@ AC_CHECK_HEADER(
[AC_MSG_ERROR([Could not find the header regex.h, needed to build fish])] [AC_MSG_ERROR([Could not find the header regex.h, needed to build fish])]
) )
#
# Detect nanoseconds fields in struct stat
#
AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
# #
# On some platforms (Solaris 10) adding -std=c99 in turn requires that # On some platforms (Solaris 10) adding -std=c99 in turn requires that

View file

@ -379,17 +379,6 @@ static size_t calc_prompt_lines(const wcstring &prompt)
} }
return result; return result;
} }
/**
Test if there is space between the time fields of struct stat to
use for sub second information. If so, we assume this space
contains the desired information.
*/
static int room_for_usec(struct stat *st)
{
int res = ((&(st->st_atime) + 2) == &(st->st_mtime) &&
(&(st->st_atime) + 4) == &(st->st_ctime));
return res;
}
/** /**
Stat stdout and stderr and save result. Stat stdout and stderr and save result.
@ -456,11 +445,13 @@ static void s_check_status(screen_t *s)
int changed = (s->prev_buff_1.st_mtime != s->post_buff_1.st_mtime) || int changed = (s->prev_buff_1.st_mtime != s->post_buff_1.st_mtime) ||
(s->prev_buff_2.st_mtime != s->post_buff_2.st_mtime); (s->prev_buff_2.st_mtime != s->post_buff_2.st_mtime);
if (room_for_usec(&s->post_buff_1)) #if defined HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
{ changed = changed || s->prev_buff_1.st_mtimespec.tv_nsec != s->post_buff_1.st_mtimespec.tv_nsec ||
changed = changed || ((&s->prev_buff_1.st_mtime)[1] != (&s->post_buff_1.st_mtime)[1]) || s->prev_buff_2.st_mtimespec.tv_nsec != s->post_buff_2.st_mtimespec.tv_nsec;
((&s->prev_buff_2.st_mtime)[1] != (&s->post_buff_2.st_mtime)[1]); #elif defined HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
} changed = changed || s->prev_buff_1.st_mtim.tv_nsec != s->post_buff_1.st_mtim.tv_nsec ||
s->prev_buff_2.st_mtim.tv_nsec != s->post_buff_2.st_mtim.tv_nsec;
#endif
if (changed) if (changed)
{ {