Using %z in printf is not portable

Bug #1952074 reported by Dirk Zimoch
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
New
Undecided
Unassigned

Bug Description

Some code in EPICS uses printf with the z format modifier for size_t arguments, as in "%zu". This is not portable. VxWorks (at least up to version 6.9.0) does not understand this and prints "zu" and then shifts all the remaining arguments to the wrong format specifier!
Older Windows versions use "%Iu" for the same purpose.

Affected code:
modules/libcom/src/error/errlog.c (2x)
modules/libcom/test/epicsErrlogTest.c
modules/libcom/test/yajl_test.c (2x)
modules/pvAccess/pvtoolsSrc/pvlist.cpp (2x)
modules/pvAccess/src/ioc/reftrackioc.cpp (2x)
modules/pvAccess/src/remote/blockingUDPTransport.cpp (4x)
modules/pvAccess/src/remote/codec.cpp (2x)
modules/pvAccess/src/remote/transportRegistry.cpp
modules/pvAccess/src/server/responseHandlers.cpp
modules/pvAccess/testApp/remote/testChannelConnect.cpp
modules/pvAccess/testApp/remote/testmonitorfifo.cpp (4x)
modules/pvData/src/factory/FieldCreateFactory.cpp (2x)
modules/pvData/testApp/pv/performstruct.cpp (2x)
modules/pvData/testApp/pv/testPVData.cpp
modules/pva2pva/pdbApp/pdbgroup.cpp
modules/pva2pva/pdbApp/pvalink.cpp (3x)
modules/pva2pva/pdbApp/pvalink_jlif.cpp
modules/pva2pva/testApp/testpdb.cpp (2x)

summary: - Using %z in printf is not portavle
+ Using %z in printf is not portable
description: updated
Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

I suggest to #define an osd macro to be used with the printf format string, like those in inttypes.h (which also does not support size_t).

description: updated
Revision history for this message
Ralph Lange (ralph-lange) wrote :

The problem is that size_t has a different size (!) on different implementations.

The usual (only?) way to get this portable is to cast the argument to something like 'unsigned long long' and use the matching format specifier.

Revision history for this message
rivers (rivers) wrote :

This issue was discussed in a previous bug report.

https://bugs.launchpad.net/epics-base/+bug/1740426

Revision history for this message
rivers (rivers) wrote :

I believe %z is supported in Visual Studio 2015 and later. Have we said that older versions are no longer supported?

I have not tested %z on vxWorks 6.9.4.1, which is what we use at the APS, but I think Andrew would have noticed if it did not work? What is the minimum version of vxWorks currently supported?

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

Simple test on the vxWorks shell:
-> printf "%u %zu %u\n",1,2,3
1 zu 2

Revision history for this message
rivers (rivers) wrote :

That simple vxWorks shell test also fails on 6.9.4.1.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.