Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with code generation #6604

Closed
Ekopalypse opened this issue Oct 11, 2020 · 1 comment
Closed

Issue with code generation #6604

Ekopalypse opened this issue Oct 11, 2020 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@Ekopalypse
Copy link
Contributor

Using the code provided below results in unexpected behavior.
Current workaround is to use the byte array .clone() function.

V version:
OS:

OS: windows, Microsoft Windows 7 Professional v7601 64-bit
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz
CC version: N/A

vroot: D:\ProgramData\Compiler\v
vexe: D:\ProgramData\Compiler\v\v.exe
vexe mtime: 2020-10-11 19:14:05
is vroot writable: true
V full version: V 0.1.29 230e986

Git version: git version 2.19.1.windows.1
Git vroot status: 0.1.29-567-g230e9868
.git/config present: true
thirdparty/tcc: N/A

What did you do?

import crypto.md5
import crypto.sha1

const (
	npad      = []byte{len: 256, init: 0}
)


fn encode(hash_func fn(bytes []byte) []byte, blocksize int, key []byte, text []byte) {
	mut b_key := []byte{}
	if key.len <= blocksize { 
		b_key = key  //.clone()
	} else { 
		b_key = hash_func(key) 
	}

	println(b_key)

	if b_key.len < blocksize {
		b_key << npad[..blocksize - b_key.len]
	}
}

fn main() {
	keys := [[byte(0xb), 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb]]
	text := ['Hi There'.bytes()]

	for i, key in keys {
		encode(md5.sum, md5.block_size, key, text[i])
		encode(sha1.sum, sha1.block_size, key, text[i])
	}
}

What did you expect to see?

[`\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`]
[`\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`]

What did you see instead?

[`\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`, `\v`]
[0xc0, 0, `\0`, `\0`, `\0`, `\0`, `\0`, `\0`, X, 0x01, -, `\0`, `\0`, `\0`, `\0`, `\0`]
@Ekopalypse Ekopalypse added the Bug This tag is applied to issues which reports bugs. label Oct 11, 2020
@crthpl
Copy link
Member

crthpl commented May 17, 2021

Duplicate of #10011

@crthpl crthpl marked this as a duplicate of #10011 May 17, 2021
@crthpl crthpl closed this as completed May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

2 participants