diff --git a/contrib/uuid-ossp/expected/uuid_ossp.out b/contrib/uuid-ossp/expected/uuid_ossp.out index f393e86..c14db22 100644 --- a/contrib/uuid-ossp/expected/uuid_ossp.out +++ b/contrib/uuid-ossp/expected/uuid_ossp.out @@ -77,3 +77,18 @@ SELECT uuid_generate_v4()::text ~ '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9] t (1 row) +DO $_$ +DECLARE + u text; + i int; + c int; +BEGIN + FOR i in 1..32 LOOP + u := substr(uuid_generate_v1mc()::text, 25, 2); + EXECUTE 'SELECT x''' || u || '''::int & 3' INTO c; + IF c <> 3 THEN + RAISE WARNING 'v1mc broken'; + END IF; + END LOOP; +END; +$_$; diff --git a/contrib/uuid-ossp/sql/uuid_ossp.sql b/contrib/uuid-ossp/sql/uuid_ossp.sql index 8f22417..61a44a8 100644 --- a/contrib/uuid-ossp/sql/uuid_ossp.sql +++ b/contrib/uuid-ossp/sql/uuid_ossp.sql @@ -17,3 +17,20 @@ SELECT uuid_generate_v3(uuid_ns_dns(), 'www.widgets.com'); SELECT uuid_generate_v5(uuid_ns_dns(), 'www.widgets.com'); SELECT uuid_generate_v4()::text ~ '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$'; + +DO $_$ +DECLARE + u text; + i int; + c int; +BEGIN + FOR i in 1..32 LOOP + u := substr(uuid_generate_v1mc()::text, 25, 2); + EXECUTE 'SELECT x''' || u || '''::int & 3' INTO c; + IF c <> 3 THEN + RAISE WARNING 'v1mc broken'; + END IF; + END LOOP; +END; +$_$; + diff --git a/contrib/uuid-ossp/uuid-ossp.c b/contrib/uuid-ossp/uuid-ossp.c index bc29ade..7803dbe 100644 --- a/contrib/uuid-ossp/uuid-ossp.c +++ b/contrib/uuid-ossp/uuid-ossp.c @@ -460,6 +460,10 @@ uuid_generate_v1mc(PG_FUNCTION_ARGS) uuid_t uu; uuid_generate_random(uu); + + /* set IEEE802 multicast and local-admin bits */ + ((dce_uuid_t *)&uu)->node[0] |= 0x03; + uuid_unparse(uu, strbuf); buf = strbuf + 24; #else /* BSD */ @@ -472,7 +476,7 @@ uuid_generate_v1mc(PG_FUNCTION_ARGS) #endif return uuid_generate_internal(UUID_MAKE_V1 | UUID_MAKE_MC, NULL, - buf, buf ? 13 : 0); + buf, 13); }