Skip to content

Commit a0cbd91

Browse files
authored
Merge pull request #47 from SpringQL/fix/blob-len
fix: CInsufficient check for memcpy
2 parents 364fd4f + 999abd5 commit a0cbd91

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Also check the changes in springql-core: <https://github.com/SpringQL/SpringQL/b
1313
<!-- markdownlint-disable MD024 -->
1414
## [Unreleased]
1515

16+
## [v0.13.0+3]
17+
18+
### Fixed
19+
20+
- `spring_column_blob()`'s `out_len` check. ([#47](https://github.com/SpringQL/SpringQL-client-c/pull/47))
21+
1622
## [v0.13.0+2]
1723

1824
### Added
@@ -67,8 +73,10 @@ Depends on springql-core v0.7.1.
6773
[Semantic Versioning]: https://semver.org/
6874

6975
<!-- Versions -->
70-
[Unreleased]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.13.0...HEAD
76+
[Unreleased]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.13.0+3...HEAD
7177
[Released]: https://github.com/SpringQL/SpringQL-client-c/releases
78+
[v0.13.0+3]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.13.0+2...v0.13.0+3
79+
[v0.13.0+2]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.13.0...v0.13.0+2
7280
[v0.13.0]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.12.0...v0.13.0
7381
[v0.12.0]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.11.0...v0.12.0
7482
[v0.11.0]: https://github.com/SpringQL/SpringQL-client-c/compare/v0.9.0+2...v0.11.0

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "springql-client-c"
3-
version = "0.13.0+2"
3+
version = "0.13.0+3"
44

55
authors = ["Sho Nakatani <[email protected]>"]
66
license = "MIT OR Apache-2.0"

src/c_mem.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// This file is part of https://github.com/SpringQL/SpringQL-client-c which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details.
22

33
use std::{
4+
ffi::c_void,
45
os::raw::{c_char, c_int},
5-
ptr, slice, ffi::c_void,
6+
ptr, slice,
67
};
78

89
use log::warn;
@@ -15,6 +16,7 @@ use crate::spring_errno::SpringErrno;
1516
/// - `< 0`: SpringErrno
1617
pub(super) fn strcpy(src: &str, dest_buf: *mut c_char, dest_len: c_int) -> c_int {
1718
if src.len() >= dest_len as usize {
19+
// `==` is not sufficient (dest needs null termination)
1820
warn!("dest_len is smaller than src.");
1921
warn!(
2022
"Expected at least {} bytes but got {}",
@@ -41,13 +43,9 @@ pub(super) fn strcpy(src: &str, dest_buf: *mut c_char, dest_len: c_int) -> c_int
4143
/// - `> 0`: the length of `src`.
4244
/// - `< 0`: SpringErrno
4345
pub(super) fn memcpy(src: &[u8], dest_buf: *mut c_void, dest_len: c_int) -> c_int {
44-
if src.len() >= dest_len as usize {
46+
if src.len() > dest_len as usize {
4547
warn!("dest_len is smaller than src.");
46-
warn!(
47-
"Expected at least {} bytes but got {}",
48-
src.len() + 1,
49-
dest_len
50-
);
48+
warn!("Expected at least {} bytes but got {}", src.len(), dest_len);
5149
return SpringErrno::CInsufficient as c_int;
5250
}
5351

0 commit comments

Comments
 (0)