On 2025-04-14 Mo 12:28 PM, Andrew Dunstan wrote:



I'm also not sure about the double sscanf() business there ... There
must be a better way to do this.



Yes, probably. I'll look into that if you like.




something like this?


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index ff4bb320fc9..a600f7d9a3b 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -1053,26 +1053,32 @@ get_dbname_oid_list_from_mfile(const char *dumpdirpath, SimpleOidStringList *dbn
 	while ((fgets(line, MAXPGPATH, pfile)) != NULL)
 	{
 		Oid			db_oid = InvalidOid;
-		char		db_oid_str[MAXPGPATH + 1] = "";
 		char	   *dbname;
+		char       *p = line;
 
 		/* Extract dboid. */
-		sscanf(line, "%u", &db_oid);
-		sscanf(line, "%20s", db_oid_str);
+		while(isdigit(*p))
+			p++;
+		if (p > line && *p == ' ')
+		{
+			sscanf(line, "%u", &db_oid);
+			p++;
+		}
 
 		/* dbname is the rest of the line */
-		dbname = line + strlen(db_oid_str) + 1;
+		dbname = p;
 
 		/* Remove \n from dbname. */
 		dbname[strlen(dbname) - 1] = '\0';
 
-		pg_log_info("found database \"%s\" (OID: %u) in \"%s\"",
-					dbname, db_oid, map_file_path);
-
 		/* Report error and exit if the file has any corrupted data. */
 		if (!OidIsValid(db_oid) || strlen(dbname) == 0)
 			pg_fatal("invalid entry in \"%s\" at line : %d", map_file_path,
 					 count + 1);
+		else
+			pg_log_info("found database \"%s\" (OID: %u) in \"%s\"",
+						dbname, db_oid, map_file_path);
+
 
 		simple_oid_string_list_append(dbname_oid_list, db_oid, dbname);
 		count++;

Reply via email to