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

Prevent declaring a dynamic-sized string with a literal #760

Closed
nosoop opened this issue Jan 28, 2018 · 2 comments
Closed

Prevent declaring a dynamic-sized string with a literal #760

nosoop opened this issue Jan 28, 2018 · 2 comments

Comments

@nosoop
Copy link
Contributor

@nosoop nosoop commented Jan 28, 2018

This compiles (tested as of latest dev branch), but produces unexpected results:

#pragma semicolon 1
#include <sourcemod>

#pragma newdecls required

public void OnPluginStart() {
	// disregard the redundant code warning
	if (false) {
		char sample_text[] = "unreachable";
		PrintToServer("%s (should be unreachable)", sample_text);
	} else {
		char[] sample_text2 = "else";
		PrintToServer("%s (should be else)", sample_text2);
	}
}

This outputs "unreachable (should be else)". I spent an embarrassingly long time trying to figure out why it was using the wrong string, along with various other weird behaviors.

Attempting to use a string literal in a non-fixed char array declaration should probably throw a compile-time error.

@Headline

This comment has been minimized.

Copy link
Member

@Headline Headline commented Feb 4, 2018

This looks to me like a sourcepawn bug, perhaps you should recreate this issue on the sp project page

@asherkin

This comment has been minimized.

Copy link
Member

@asherkin asherkin commented Feb 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.