mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
Merge pull request #887 from jbcrail/fix-cksum-overflow
cksum: resolve msvc unsafe issue
This commit is contained in:
commit
ccf604f1f9
1 changed files with 13 additions and 1 deletions
|
@ -17,6 +17,7 @@ extern crate uucore;
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, stdin, Read, Write, BufReader};
|
use std::io::{self, stdin, Read, Write, BufReader};
|
||||||
|
#[cfg(not(windows))]
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -42,6 +43,16 @@ fn crc_final(mut crc: u32, mut length: usize) -> u32 {
|
||||||
!crc
|
!crc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn init_byte_array() -> Vec<u8> {
|
||||||
|
vec![0; 1024 * 1024]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn init_byte_array() -> [u8; 1024*1024] {
|
||||||
|
unsafe { mem::uninitialized() }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
||||||
let mut crc = 0u32;
|
let mut crc = 0u32;
|
||||||
|
@ -58,7 +69,7 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut bytes: [u8; 1024 * 1024] = unsafe { mem::uninitialized() };
|
let mut bytes = init_byte_array();
|
||||||
loop {
|
loop {
|
||||||
match rd.read(&mut bytes) {
|
match rd.read(&mut bytes) {
|
||||||
Ok(num_bytes) => {
|
Ok(num_bytes) => {
|
||||||
|
@ -73,6 +84,7 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
||||||
Err(err) => return Err(err)
|
Err(err) => return Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Ok((0 as u32,0 as usize))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue