Mercurial > hg
comparison mercurial/parsers.c @ 24879:b3142ea2a0d4 stable
parsers: avoid signed integer overflow in calculation of leaf-node index
If v = -INT_MAX - 1, -v would exceed INT_MAX. I don't think this would cause
problems such as issue4627, but we can't blame it as a compiler bug because
signed integer overflow is undefined in C.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 29 Apr 2015 23:07:34 +0900 |
parents | f2fd087a75ef |
children | 22438cfd11b5 50a6c3c55db1 |
comparison
equal
deleted
inserted
replaced
24878:e530cde6d115 | 24879:b3142ea2a0d4 |
---|---|
1310 | 1310 |
1311 if (v < 0) { | 1311 if (v < 0) { |
1312 const char *n; | 1312 const char *n; |
1313 Py_ssize_t i; | 1313 Py_ssize_t i; |
1314 | 1314 |
1315 v = -v - 1; | 1315 v = -(v + 1); |
1316 n = index_node(self, v); | 1316 n = index_node(self, v); |
1317 if (n == NULL) | 1317 if (n == NULL) |
1318 return -2; | 1318 return -2; |
1319 for (i = level; i < maxlevel; i++) | 1319 for (i = level; i < maxlevel; i++) |
1320 if (getnybble(node, i) != nt_level(n, i)) | 1320 if (getnybble(node, i) != nt_level(n, i)) |
1366 if (v == 0) { | 1366 if (v == 0) { |
1367 n->children[k] = -rev - 1; | 1367 n->children[k] = -rev - 1; |
1368 return 0; | 1368 return 0; |
1369 } | 1369 } |
1370 if (v < 0) { | 1370 if (v < 0) { |
1371 const char *oldnode = index_node(self, -v - 1); | 1371 const char *oldnode = index_node(self, -(v + 1)); |
1372 int noff; | 1372 int noff; |
1373 | 1373 |
1374 if (!oldnode || !memcmp(oldnode, node, 20)) { | 1374 if (!oldnode || !memcmp(oldnode, node, 20)) { |
1375 n->children[k] = -rev - 1; | 1375 n->children[k] = -rev - 1; |
1376 return 0; | 1376 return 0; |