Inconsistent snprintf format specification parsing

Bug #221979 reported by Dmitry Pankratov
20
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mingw32 (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

Binary package hint: mingw32-runtime

OS: Ubuntu 8.04/AMD64.
Package: 3.13-1

Description:
The snprintf library function incorrectly parses the "%lu" format specifier as "unsigned long long" instead of "unsigned long" resulting in incorrect value formatting.

Example:
#include <stdio.h>
int main() {
    char buf[256];
    snprintf(buf, 256, "%lu", (size_t)12345678);
    printf(buf);
    return 0;
}

Prints:
9151369040453460302

Instead of:
12345678

Other functions like printf and sprintf do work fine.
Native Linux GCC compiler version 4.2.3 produces correct code in both 32 and 64 mode.
When replacing (size_t) with (unsigned long long) the above code works fine also in mingw32.

Revision history for this message
Dmitry Pankratov (dremon) wrote :

Looks like this problem is fixed in the mingw-runtime 3.14. Is it possible to update Ubuntu package with the latest upstream version?

description: updated
Revision history for this message
Dmitry Pankratov (dremon) wrote :

I've made a patch for the current mingw32-runtime source package. Should fix the problem.

Revision history for this message
Martin Aumueller (aumuell) wrote :

Not only the %lu format specifier is affected, at least %ld,%li and %lx show the same behaviour.

Also the mingw-runtime in Ubuntu 8.10 on x86_64 (3.13-1) seems to be affected.

Revision history for this message
David Favro (launchpad-net-meta-dynamic) wrote :

This problem still exists in 9.04 beta. The patch has been posted here for a year already, and it's trivial to see that it is indeed a good fix. If the reason that the patch hasn't been applied yet is that it's already been fixed upstream, then why aren't we using the newer upstream version? One way or the other, this is an easy one to fix and very annoying to remain broken. The bug hasn't even been assigned to anyone! Come on, guys.

Revision history for this message
Rohan Garg (rohangarg) wrote :

Hi
Could you please check if this still happens with the latest package from our maverick archives? I tried to patch the files but it seems that upstream has removed the files which had to be patched.Please add a new patch and ill work on this.

Changed in mingw32 (Ubuntu):
status: New → Incomplete
Revision history for this message
Dmitry Pankratov (dremon) wrote :

The mingw32-runtime is based now on version 3.15.2 which has this problem fixed.

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for mingw32 (Ubuntu) because there has been no activity for 60 days.]

Changed in mingw32 (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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