os.v: getline fixed conditional jump on uninitialized values

pull/702/head
Henrixounez 2019-06-27 12:14:33 +02:00 committed by Alexander Medvednikov
parent b61d2ac346
commit fda7caef93
1 changed files with 5 additions and 2 deletions

View File

@ -408,9 +408,12 @@ pub fn filename(path string) string {
}
// get_line returns a one-line string from stdin
//u64 is used because C.getline needs a size_t as second argument
//Otherwise, it would cause a valgrind warning and may be dangerous
//Malloc takes an int as argument so a cast has to be made
pub fn get_line() string {
max := 256
buf := malloc(max)
max := u64(256)
buf := malloc(int(max))
nr_chars := C.getline(&buf, &max, stdin)
if nr_chars == 0 {
return ''