aboutsummaryrefslogtreecommitdiff
path: root/src/option.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-19 13:12:04 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-24 10:32:47 -0300
commitdb23cb05d1d40487007b3c93dd54fab290fd02b7 (patch)
treee43f5a0cc4314e239015de512b636c93a005dc83 /src/option.c
parent9a5b3eee5f73594f5e3f71411f6a7d4fe2b9da55 (diff)
downloadrneovim-db23cb05d1d40487007b3c93dd54fab290fd02b7.tar.gz
rneovim-db23cb05d1d40487007b3c93dd54fab290fd02b7.tar.bz2
rneovim-db23cb05d1d40487007b3c93dd54fab290fd02b7.zip
Use /2 and 2* instead of >>1 and <<1 which are tricky with signed types
Today's compilers generate shift instructions to perform division and multiplications by powers of 2 [1]. `(x >> 1)` looks straightforward enough, but if x is signed the code will fail when x < 0. The compiler knows better: use `x / 2`. That's why we have code like this: (long)((long_u)Rows >> 1)) instead of the cleaner version that generates the same or better machine code: Rows / 2 [1] http://goo.gl/J4WpG7
Diffstat (limited to 'src/option.c')
-rw-r--r--src/option.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/option.c b/src/option.c
index a12b3d879a..7bf01bafac 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2042,8 +2042,8 @@ void set_init_1(void)
/* Initialize the 'cdpath' option's default value. */
cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
if (cdpath != NULL) {
- buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
- if (buf != NULL) {
+ buf = xmalloc(2 * STRLEN(cdpath) + 2);
+ {
buf[0] = ','; /* start with ",", current dir first */
j = 1;
for (i = 0; cdpath[i] != NUL; ++i) {
@@ -2376,7 +2376,7 @@ void set_init_2(void)
* 'scroll' defaults to half the window height. Note that this default is
* wrong when the window height changes.
*/
- set_number_default("scroll", (long)((long_u)Rows >> 1));
+ set_number_default("scroll", Rows / 2);
idx = findoption((char_u *)"scroll");
if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
set_option_default(idx, OPT_LOCAL, p_cp);