[Mesa-dev] [PATCH v3] egl/dri2: use drm macros to construct device name
Jonathan Gray
jsg at jsg.id.au
Wed Apr 2 23:26:51 PDT 2014
On Wed, Apr 02, 2014 at 11:09:09PM -0700, Matt Turner wrote:
> On Wed, Apr 2, 2014 at 10:22 PM, Jonathan Gray <jsg at jsg.id.au> wrote:
> > Don't hardcode /dev/dri/card0 but instead use the drm
> > macros which allows the correct /dev/drm0 device to be
> > opened on OpenBSD.
> >
> > v2: use snprintf and fallback to /dev/dri/card0
> > v3: check for snprintf truncation
> >
> > Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
> > ---
> > src/egl/drivers/dri2/platform_drm.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
> > index 2f7edb9..9a7633a 100644
> > --- a/src/egl/drivers/dri2/platform_drm.c
> > +++ b/src/egl/drivers/dri2/platform_drm.c
> > @@ -492,7 +492,12 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
> >
> > gbm = disp->PlatformDisplay;
> > if (gbm == NULL) {
> > - fd = open("/dev/dri/card0", O_RDWR);
> > + char buf[64];
> > + int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0);
> > + if (n != -1 && n < sizeof(buf))
>
> n <= sizeof(buf), right? snprintf writes up to sizeof(buf) bytes,
> including the nul character.
>
> With that fixed,
>
> Reviewed-by: Matt Turner <mattst88 at gmail.com>
No, see the description from the manual page:
http://www.openbsd.org/cgi-bin/man.cgi?query=snprintf&sektion=3&format=html
snprintf() and vsnprintf() will write at most size-1 of the characters
printed into the output string (the size'th character then gets the
terminating `\0'); if the return value is greater than or equal to the
size argument, the string was too short and some of the printed
characters were discarded.
So n == sizeof(buf) is a truncation.
More information about the mesa-dev
mailing list