Skip to content

[Bug]: NDK header patches use non reserved identifiers in local variables #30545

Description

@ngtv2409

Problem description

Title. Here is an example:

https://github.com/termux/termux-packages/blob/master/ndk-patches/23c/stdio.h.patch

int open(const char*, int, ...);
extern pid_t getpid();
extern int unlink(const char*);
void free(void* p);
uint32_t arc4random(void);
static __inline__ FILE* tmpfile() {
	int p = getpid();
	char* path;
	int i;
	for (i = 0; i < 100; i++) {
		unsigned int r = arc4random();
		if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL;
		int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600);
		if (fd >= 0) {
			FILE* result = fdopen(fd, "w+");
			unlink(path);
		free(path);
			return result;
		}
		free(path);
	}
	return NULL;
}

r, p, result, ... are unreserved identifiers.

This is a problem if there is a macro definition clashing with these identifiers. Although unlikely for any real codebases.

What steps will reproduce the bug?

Source code.

What is the expected behavior?

According to the C23 standard:

7.1.3 reserves certain names and patterns of names that an implementation can use in headers. All other names are not reserved, and a conforming implementation is not permitted to use them

https://cigix.me/c23#footnote456

System information

Unrelated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug reportSomething is not working properly

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions