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

Unsigned long should be used for 0 <= value <= 18446744073709551615 #80

Open
gatopeich opened this issue Jun 30, 2021 · 2 comments
Open

Comments

@gatopeich
Copy link

Compiler is rightly complaining about 18446744073709551615L used in this constraint:

	usageCountUL					INTEGER (0..18446744073709551615),

==>

memb_usageCountUL_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
			asn_app_constraint_failed_f *ctfailcb, void *app_key) {
	const INTEGER_t *st = (const INTEGER_t *)sptr;
	long value;
	
	if(!sptr) {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	if(asn_INTEGER2long(st, &value)) {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: value too large (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	if((value >= 0L && value <= 18446744073709551615L)) {
		/* Constraint check succeeded */
		return 0;
	} else {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: constraint failed (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
}

Instead, the value should be unsigned long, parsed with asn_INTEGER2ulong, and the number written with UL suffix.

Note: 18446744073709551615 == max 64-bits value = ULONG_MAX

@mouse07410
Copy link
Owner

Do you have a suggested PR?

@gatopeich
Copy link
Author

gatopeich commented Jul 1, 2021

First I wanted to be sure that I am not missing some tweak or setting, since asn_INTEGER2ulong is there, I hoped somebody would give a quick solution...
... Like "use -fwide-types" :-)
(though that would break a lot of my existing code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants