|
50 | 50 | #define M_PI 3.14159265358979323846 |
51 | 51 | #endif |
52 | 52 |
|
53 | | -#include <unistd.h> // TODO: Windows |
| 53 | +#if !defined(_WIN32) && !defined(_WIN64) |
| 54 | +#include <unistd.h> |
| 55 | +#else |
| 56 | +#include <fcntl.h> |
| 57 | +#include <io.h> |
| 58 | +#endif |
| 59 | + |
54 | 60 |
|
55 | 61 | Fraction::Fraction(int32_t num, int32_t den) |
56 | 62 | { |
@@ -155,7 +161,7 @@ bool Fraction::is_valid() const |
155 | 161 | return denominator != 0; |
156 | 162 | } |
157 | 163 |
|
158 | | -uint32_t from_fourcc(const char* string) |
| 164 | +static uint32_t from_fourcc(const char* string) |
159 | 165 | { |
160 | 166 | return ((string[0] << 24) | |
161 | 167 | (string[1] << 16) | |
@@ -1035,7 +1041,7 @@ Error Box_ftyp::parse(BitstreamRange& range) |
1035 | 1041 | m_major_brand = range.read32(); |
1036 | 1042 | m_minor_version = range.read32(); |
1037 | 1043 |
|
1038 | | - if (get_box_size() <= get_header_size() + 8) { |
| 1044 | + if (get_box_size() - 8 <= get_header_size()) { |
1039 | 1045 | // Sanity check. |
1040 | 1046 | return Error(heif_error_Invalid_input, |
1041 | 1047 | heif_suberror_Invalid_box_size, |
@@ -1406,8 +1412,15 @@ void Box_iloc::set_use_tmp_file(bool flag) |
1406 | 1412 | { |
1407 | 1413 | m_use_tmpfile = flag; |
1408 | 1414 | if (flag) { |
| 1415 | +#if !defined(_WIN32) && !defined(_WIN64) |
1409 | 1416 | strcpy(m_tmp_filename, "/tmp/libheif-XXXXXX"); |
1410 | 1417 | m_tmpfile_fd = mkstemp(m_tmp_filename); |
| 1418 | +#else |
| 1419 | + char tmpname[L_tmpnam_s]; |
| 1420 | + // TODO: check return value (errno_t) |
| 1421 | + tmpnam_s(tmpname, L_tmpnam_s); |
| 1422 | + _sopen_s(&m_tmpfile_fd, tmpname, _O_CREAT | _O_TEMPORARY | _O_TRUNC | _O_RDWR, _SH_DENYRW, _S_IREAD | _S_IWRITE); |
| 1423 | +#endif |
1411 | 1424 | } |
1412 | 1425 | } |
1413 | 1426 |
|
@@ -1629,7 +1642,11 @@ Error Box_iloc::append_data(heif_item_id item_ID, |
1629 | 1642 | extent.length = data.size(); |
1630 | 1643 |
|
1631 | 1644 | if (m_use_tmpfile && construction_method==0) { |
| 1645 | +#if !defined(_WIN32) && !defined(_WIN64) |
1632 | 1646 | ssize_t cnt = ::write(m_tmpfile_fd, data.data(), data.size()); |
| 1647 | +#else |
| 1648 | + int cnt = _write(m_tmpfile_fd, data.data(), data.size()); |
| 1649 | +#endif |
1633 | 1650 | if (cnt < 0) { |
1634 | 1651 | std::stringstream sstr; |
1635 | 1652 | sstr << "Could not write to tmp file: error " << errno; |
@@ -1883,7 +1900,11 @@ Error Box_iloc::write_mdat_after_iloc(StreamWriter& writer) |
1883 | 1900 |
|
1884 | 1901 | if (m_use_tmpfile) { |
1885 | 1902 | std::vector<uint8_t> data(extent.length); |
| 1903 | +#if !defined(_WIN32) && !defined(_WIN64) |
1886 | 1904 | ssize_t cnt = ::read(m_tmpfile_fd, data.data(), extent.length); |
| 1905 | +#else |
| 1906 | + int cnt = _read(m_tmpfile_fd, data.data(), extent.length); |
| 1907 | +#endif |
1887 | 1908 | if (cnt<0) { |
1888 | 1909 | std::stringstream sstr; |
1889 | 1910 | sstr << "Cannot read tmp data file, error " << errno; |
@@ -2632,7 +2653,7 @@ Error Box_ipma::parse(BitstreamRange& range) |
2632 | 2653 |
|
2633 | 2654 | int assoc_cnt = range.read8(); |
2634 | 2655 | for (int k = 0; k < assoc_cnt; k++) { |
2635 | | - PropertyAssociation association; |
| 2656 | + PropertyAssociation association{}; |
2636 | 2657 |
|
2637 | 2658 | uint16_t index; |
2638 | 2659 | if (get_flags() & 1) { |
@@ -3902,9 +3923,9 @@ Error Box_cmin::write(StreamWriter& writer) const |
3902 | 3923 | } |
3903 | 3924 |
|
3904 | 3925 |
|
3905 | | -std::array<double,9> mul(const std::array<double,9>& a, const std::array<double,9>& b) |
| 3926 | +static std::array<double,9> mul(const std::array<double,9>& a, const std::array<double,9>& b) |
3906 | 3927 | { |
3907 | | - std::array<double,9> m; |
| 3928 | + std::array<double, 9> m{}; |
3908 | 3929 |
|
3909 | 3930 | m[0] = a[0]*b[0] + a[1]*b[3] + a[2]*b[6]; |
3910 | 3931 | m[1] = a[0]*b[1] + a[1]*b[4] + a[2]*b[7]; |
|
0 commit comments