pganalyze / pg_query_go

Go library to parse and normalize SQL queries using the PostgreSQL query parser
BSD 3-Clause "New" or "Revised" License
663 stars 79 forks source link

sprintf deprecation warning #67

Closed rliebz closed 1 year ago

rliebz commented 2 years ago

I recently encountered the issue described in #66 after updating Xcode, and updating this library has restored the original functionality. After the update to pg_query_go v2.2.0, the original functionality has been restored, but I continue to get warnings:

# github.com/pganalyze/pg_query_go/v2/parser
src_port_snprintf.c:1030:11: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use
 snprintf(3) instead. [-Wdeprecated-declarations]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
src_port_snprintf.c:1212:13: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use
 snprintf(3) instead. [-Wdeprecated-declarations]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
src_port_snprintf.c:1219:13: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use
 snprintf(3) instead. [-Wdeprecated-declarations]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'

Seems to point to a few calls to sprintf that presumably should be replaced with snprintf, for example: https://github.com/pganalyze/pg_query_go/blob/920eb98a2b57c0631edecda018671be92fec63fb/parser/src_port_snprintf.c#L1030

For context, this is when running https://github.com/kyleconroy/sqlc, but looks like the warnings are stemming from here.

christeredvartsen commented 2 years ago

Same issue here. xcode-select --version is reporting 2396, and I started getting these warnings after bumping sqlc to v1.16.0, which seems to be using v2.2.0 of this lib.

lfittl commented 2 years ago

Thanks for the report!

The Postgres project has fixed this upstream in https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=450ee701261a7ff5fe35842b91384eea46e81c2e - we will likely pull in this commit when we update the parser to Postgres 14/15 in the next weeks, which should resolve the issue.

17twenty commented 2 years ago

Can confirm - pulling in that source code into src_port_snprintf.c wholesale fixed my build

Yiwen-Gao commented 1 year ago

Hello! I'm also seeing the warnings and was wondering when the upstream would be pulled in. Thanks!

lfittl commented 1 year ago

@Yiwen-Gao We have a draft PR for Postgres 15 here, that I think will fix those warnings: https://github.com/pganalyze/pg_query_go/pull/69 - we'll likely have this merged after the holidays (i.e. in early January).

gnvk commented 1 year ago

https://github.com/pganalyze/pg_query_go/pull/69 seems to be merged.

lfittl commented 1 year ago

This has now been released as v4.2.1, thus closing this issue. Please let us know in case you still see this after upgrading!

christeredvartsen commented 1 year ago

Can confirm that the warnings are now gone, at least in my case. :) Thanks!