<commit_before>/*----------------------------------------------------------------------
 *
 * pgquarrel -- comparing database schemas
 *
 * privileges.c
 *     Generate GRANT / REVOKE commands
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * GRANT ON TABLE
 * GRANT (columns) ON TABLE
 * GRANT ON SEQUENCE
 * GRANT ON DOMAIN
 * GRANT ON FUNCTION
 * GRANT ON LANGUAGE
 * GRANT ON SCHEMA
 * GRANT ON TYPE
 * GRANT ON DATABASE
 * GRANT ON FOREIGN DATA WRAPPER
 * GRANT ON FOREIGN SERVER
 * GRANT ON TABLESPACE
 *
 * REVOKE ON TABLE
 * REVOKE (columns) ON TABLE
 * REVOKE ON SEQUENCE
 * REVOKE ON DOMAIN
 * REVOKE ON FUNCTION
 * REVOKE ON LANGUAGE
 * REVOKE ON SCHEMA
 * REVOKE ON TYPE
 * REVOKE ON DATABASE
 * REVOKE ON FOREIGN DATA WRAPPER
 * REVOKE ON FOREIGN SERVER
 * REVOKE ON TABLESPACE
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * Copyright (c) 2015-2018, <NAME>
 *
 * ---------------------------------------------------------------------
 */
#include "privileges.h"


/*
 * We do not check for privilege correctness. We assume that the object accepts
 * all privileges informed. This function returns a allocated string that is a
 * list of the described privileges.
 */
char *
formatPrivileges(char *s, char *cols)
{
#define	MAX_KEYWORD_LEN		10	/* maximum keyword length */

	char	*ret, *ptr;
	size_t	len;
	size_t	collen = 0;
	size_t	coltotallen = 0;
	bool	first_item = true;
	int		i;

	if (s == NULL)
		return NULL;

	len = strlen(s);
	if (cols)
	{
		collen = strlen(cols);
		coltotallen = collen + 3;	/* 3 => space + parentheses */
	}

	ret = (char *) malloc(((len * MAX_KEYWORD_LEN + (len - 1) * 2) + coltotallen) *
						  sizeof(char));
	ret[0] = '\0';
	ptr = ret;

	for (i = 0; i < len; i++)
	{
		if (first_item)
			first_item = false;
		else
		{
			strncpy(ptr, ", ", 2);
			ptr += 2;
		}

		switch (s[i])
		{
			case 'r':	/* SELECT */
				strncpy(ptr, "SELECT", 6);
				ptr += 6;
				break;
			case 'U':	/* USAGE */
				strncpy(ptr, "USAGE", 5);
				ptr += 5;
				break;
			case 'a':	/* INSERT */
				strncpy(ptr, "INSERT", 6);
				ptr += 6;
				break;
			case 'x':	/* REFERENCES */
				strncpy(ptr, "REFERENCES", 10);
				ptr += 10;
				break;
			case 'd':	/* DELETE */
				strncpy(ptr, "DELETE", 6);
				ptr += 6;
				break;
			case 't':	/* TRIGGER */
				strncpy(ptr, "TRIGGER", 7);
				ptr += 7;
				break;
			case 'D':	/* TRUNCATE */
				strncpy(ptr, "TRUNCATE", 8);
				ptr += 8;
				break;
			case 'w':	/* UPDATE */
				strncpy(ptr, "UPDATE", 6);
				ptr += 6;
				break;
			case 'X':	/* EXECUTE */
				strncpy(ptr, "EXECUTE", 7);
				ptr += 7;
				break;
			case 'C':	/* CREATE */
				strncpy(ptr, "CREATE", 6);
				ptr += 6;
				break;
			case 'c':	/* CONNECT */
				strncpy(ptr, "CONNECT", 7);
				ptr += 7;
				break;
			case 'T':	/* TEMPORARY */
				strncpy(ptr, "TEMPORARY", 9);
				ptr += 9;
				break;
		}

		if (collen > 0)
		{
			strncpy(ptr, " (", 2);
			ptr += 2;
			strncpy(ptr, cols, collen);
			ptr += collen;
			strncpy(ptr, ")", 1);
			ptr += 1;
		}
	}

	*ptr = '\0';

	logNoise("privileges: %s", ret);

	return ret;
}<commit_msg>Avoid strncpy warning<commit_after>/*----------------------------------------------------------------------
 *
 * pgquarrel -- comparing database schemas
 *
 * privileges.c
 *     Generate GRANT / REVOKE commands
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * GRANT ON TABLE
 * GRANT (columns) ON TABLE
 * GRANT ON SEQUENCE
 * GRANT ON DOMAIN
 * GRANT ON FUNCTION
 * GRANT ON LANGUAGE
 * GRANT ON SCHEMA
 * GRANT ON TYPE
 * GRANT ON DATABASE
 * GRANT ON FOREIGN DATA WRAPPER
 * GRANT ON FOREIGN SERVER
 * GRANT ON TABLESPACE
 *
 * REVOKE ON TABLE
 * REVOKE (columns) ON TABLE
 * REVOKE ON SEQUENCE
 * REVOKE ON DOMAIN
 * REVOKE ON FUNCTION
 * REVOKE ON LANGUAGE
 * REVOKE ON SCHEMA
 * REVOKE ON TYPE
 * REVOKE ON DATABASE
 * REVOKE ON FOREIGN DATA WRAPPER
 * REVOKE ON FOREIGN SERVER
 * REVOKE ON TABLESPACE
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * Copyright (c) 2015-2018, <NAME>
 *
 * ---------------------------------------------------------------------
 */
#include "privileges.h"


/*
 * We do not check for privilege correctness. We assume that the object accepts
 * all privileges informed. This function returns a allocated string that is a
 * list of the described privileges.
 */
char *
formatPrivileges(char *s, char *cols)
{
#define	MAX_KEYWORD_LEN		10	/* maximum keyword length */

	char	*ret, *ptr;
	size_t	len;
	size_t	collen = 0;
	size_t	coltotallen = 0;
	bool	first_item = true;
	int		i;

	if (s == NULL)
		return NULL;

	len = strlen(s);
	if (cols)
	{
		collen = strlen(cols);
		coltotallen = collen + 3;	/* 3 => space + parentheses */
	}

	ret = (char *) malloc(((len * MAX_KEYWORD_LEN + (len - 1) * 2) + coltotallen) *
						  sizeof(char));
	ret[0] = '\0';
	ptr = ret;

	for (i = 0; i < len; i++)
	{
		if (first_item)
			first_item = false;
		else
		{
			strncpy(ptr, ", ", 3);
			ptr += 2;
		}

		switch (s[i])
		{
			case 'r':	/* SELECT */
				strncpy(ptr, "SELECT", 7);
				ptr += 6;
				break;
			case 'U':	/* USAGE */
				strncpy(ptr, "USAGE", 6);
				ptr += 5;
				break;
			case 'a':	/* INSERT */
				strncpy(ptr, "INSERT", 7);
				ptr += 6;
				break;
			case 'x':	/* REFERENCES */
				strncpy(ptr, "REFERENCES", 11);
				ptr += 10;
				break;
			case 'd':	/* DELETE */
				strncpy(ptr, "DELETE", 7);
				ptr += 6;
				break;
			case 't':	/* TRIGGER */
				strncpy(ptr, "TRIGGER", 8);
				ptr += 7;
				break;
			case 'D':	/* TRUNCATE */
				strncpy(ptr, "TRUNCATE", 9);
				ptr += 8;
				break;
			case 'w':	/* UPDATE */
				strncpy(ptr, "UPDATE", 7);
				ptr += 6;
				break;
			case 'X':	/* EXECUTE */
				strncpy(ptr, "EXECUTE", 8);
				ptr += 7;
				break;
			case 'C':	/* CREATE */
				strncpy(ptr, "CREATE", 7);
				ptr += 6;
				break;
			case 'c':	/* CONNECT */
				strncpy(ptr, "CONNECT", 8);
				ptr += 7;
				break;
			case 'T':	/* TEMPORARY */
				strncpy(ptr, "TEMPORARY", 10);
				ptr += 9;
				break;
		}

		if (collen > 0)
		{
			strncpy(ptr, " (", 3);
			ptr += 2;
			strncpy(ptr, cols, collen);
			ptr += collen;
			strncpy(ptr, ")", 2);
			ptr += 1;
		}
	}

	*ptr = '\0';

	logNoise("privileges: %s", ret);

	return ret;
}
{'fraction_non_alphanumeric': 0.22182700080840745, 'fraction_numerical': 0.017299919159256265, 'mean_word_length': 2.187017001545595, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4392983', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2306, 'n_words': 664}