[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-glpk] minisat: copying 32 bit integer to 64 bit pointer
From: |
Heinrich Schuchardt |
Subject: |
[Bug-glpk] minisat: copying 32 bit integer to 64 bit pointer |
Date: |
Tue, 29 Sep 2015 22:42:30 +0200 |
Hello Andrew,
on 64bit Windows unsigned long has 32 bits and a pointer has 64 bits.
The coding in minisat.c is definitely flawed.
Visual Studio 2015 shows these warnings for minisat:
..\src\minisat\minisat.c(582): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(583): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(645): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(646): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(768): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(770): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(770): warning C4312: "Typumwandlung": Konvertierung
von "unsigned long" in größeren Typ "clause *"
..\src\minisat\minisat.c(773): warning C4311: "Typumwandlung": Zeigerverkürzung
von "clause *" zu "unsigned long"
..\src\minisat\minisat.c(830): warning C4244: "=": Konvertierung von "__int64"
in "int", möglicher Datenverlust
The buggy coding is in these defines:
#define clause_from_lit(l) \
(clause*)((unsigned long)(l) + (unsigned long)(l) + 1)
#define clause_is_lit(c) \
((unsigned long)(c) & 1)
#define clause_read_lit(c) \
(lit)((unsigned long)(c) >> 1)
clause_from_lit returns a pointer to memory Nirwana.
Furthermore the unjustified assumption is made that struct clause is two byte
aligned.
This may be true for most architectures and compilers but at least on amd64 you
could also
enforce a one byte alignment by compiling with Visual C and setting /Zp1.
Best regards
Heinrich Schuchardt
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-glpk] minisat: copying 32 bit integer to 64 bit pointer,
Heinrich Schuchardt <=