• R/O
  • SSH
  • HTTPS

yash: 提交


Commit MetaInfo

修訂4189 (tree)
時間2022-08-14 23:53:34
作者magicant

Log Message

arith: Detect overflow in unary minus

Change Summary

差異

--- yash/branches/arith-error/arith.c (revision 4188)
+++ yash/branches/arith-error/arith.c (revision 4189)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* arith.c: arithmetic expansion */
3-/* (C) 2007-2019 magicant */
3+/* (C) 2007-2022 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -833,7 +833,17 @@
833833 coerce_number(info, result);
834834 if (ttype == TT_MINUS) {
835835 switch (result->type) {
836- case VT_LONG: result->v_long = -result->v_long; break;
836+ case VT_LONG:
837+#if LONG_MIN < -LONG_MAX
838+ if (result->v_long == LONG_MIN) {
839+ xerror(0, Ngt("arithmetic: overflow"));
840+ info->error = true;
841+ result->type = VT_INVALID;
842+ break;
843+ }
844+#endif
845+ result->v_long = -result->v_long;
846+ break;
837847 case VT_DOUBLE: result->v_double = -result->v_double; break;
838848 case VT_INVALID: break;
839849 default: assert(false);
Show on old repository browser