diff options
author | tyfkda <[email protected]> | 2020-01-15 09:10:10 +0900 |
---|---|---|
committer | tyfkda <[email protected]> | 2020-01-15 09:13:13 +0900 |
commit | 47922ed96c9334f2f48291f2fe9c282a80c9046f (patch) | |
tree | 67a081394d2a37266e6da2e0152c619a0c1be614 | |
parent | 8f696e93d11b4ac87a38ce7dca71b71e6f7c0d16 (diff) | |
download | xbyak-47922ed96c9334f2f48291f2fe9c282a80c9046f.tar.gz xbyak-47922ed96c9334f2f48291f2fe9c282a80c9046f.zip |
Fix segmentation fault in calc sample
Segmentation fault occurred in `calc` sample
when no variables are given from command line argument:
```
$ cd sample
$ make calc64
$ ./calc64 "" "123"
varTbl = { }
64bit mode
zsh: segmentation fault ./calc64 "" "123"
```
`put` function always access `x[0]`,
but segmentation fault occurred when `x.size() == 0`.
-rw-r--r-- | sample/calc.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sample/calc.cpp b/sample/calc.cpp index 3f4a0f9..29ad9c3 100644 --- a/sample/calc.cpp +++ b/sample/calc.cpp @@ -155,9 +155,9 @@ struct Grammar : public boost::spirit::classic::grammar<Grammar> { void put(const std::vector<double>& x) { - printf("%f", x[0]); - for (size_t i = 1, n = x.size(); i < n; i++) { - printf(", %f", x[i]); + for (size_t i = 0, n = x.size(); i < n; i++) { + if (i > 0) printf(", "); + printf("%f", x[i]); } } |