Commit eaaf8eda authored by Ludovic Rousseau's avatar Ludovic Rousseau

Fix compiler warning: output may be truncated

winscard_msg.c: In function ‘ClientSetupSession’:
winscard_msg.c:134:2: warning: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 109 [-Wstringop-truncation]
  strncpy(svc_addr.sun_path, socketName, sizeof(svc_addr.sun_path));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The source was sizeof(struct sockaddr_un) bytes long.
But the destination was sizeof(svc_addr.sun_path) bytes long only.

svc_addr is a struct sockaddr_un but the sun_path field is shorter (1
byte shorter according to the compiler) than the complete struct
sockaddr_un.
parent 2bef0948
......@@ -79,9 +79,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define SOCK_CLOEXEC 0
#endif
#define member_size(type, member) sizeof(((type *)0)->member)
char *getSocketName(void)
{
static char socketName[sizeof(struct sockaddr_un)];
static char socketName[member_size(struct sockaddr_un, sun_path)];
if ('\0' == socketName[0])
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment