Actually that sizeof in Translate (data.cpp) is plain wrong, since it
refers to sizeof(char *) which is 8 on a 64-bit OS and 4 on a 32-bit OS;
build the attached test.c with -m64 and -m32 and run to verify that:
$ gcc -m64 test.c -o test64
$ ./test64
This is really 6: 6
This is machine-dependent: 8
$ gcc -m32 test.c -o test32
$ ./test32
This is really 6: 6
This is machine-dependent: 4
Probably Chris has a 32-bit Windows machine, that's why it works.
So the rel fix is not increasing to 8 the size of _type in OBAtom
(atom.h), but rather defining OBATOM_TYPE_LEN = 6 in atom.h, setting
_type[OBATOM_TYPE_LEN] in OBAtom and replacing sizeof(to) with
OBATOM_TYPE_LEN in bool OBTypeTable::Translate(char *to, const char
*from). A new patch is attached.
Cheers,
p.
--
==========================================================
Paolo Tosco, Ph.D. Phone: +39 011 6707680
Department of Drug Science Fax: +39 011 6707687
and Technology Mob: +39 348 5537206
Via Pietro Giuria, 9
10125 Torino, Italy
http://open3dalign.org
E-mail: paolo.to...@unito.it http://open3dqsar.org
==========================================================
#include <stdio.h>
int sizeof_in_function(char *type) {
return sizeof(type);
}
int main(int argc, char **argv)
{
char type[6];
printf("This is really 6: %d\n", sizeof(type));
printf("This is machine-dependent: %d\n", sizeof_in_function(type));
return 0;
}
*** src/forcefield.cpp.orig 2012-05-18 00:22:20.875386817 +0200
--- src/forcefield.cpp 2012-05-18 00:26:12.030386712 +0200
***************
*** 779,788 ****
{
IF_OBFF_LOGLVL_LOW {
OBFFLog("\nA T O M T Y P E S\n\n");
! OBFFLog("IDX\tTYPE\n");
FOR_ATOMS_OF_MOL (a, _mol) {
! snprintf(_logbuf, BUFF_SIZE, "%d\t%s\n", a->GetIdx(), a->GetType());
OBFFLog(_logbuf);
}
}
--- 779,789 ----
{
IF_OBFF_LOGLVL_LOW {
OBFFLog("\nA T O M T Y P E S\n\n");
! OBFFLog("IDX\tTYPE\tRING\n");
FOR_ATOMS_OF_MOL (a, _mol) {
! snprintf(_logbuf, BUFF_SIZE, "%d\t%s\t%s\n", a->GetIdx(),
a->GetType(),
! (a->IsInRing() ? (a->IsAromatic() ? "AR" : "AL") : "NO"));
OBFFLog(_logbuf);
}
}
***************
*** 855,875 ****
}
if (IsSetupNeeded(mol)) {
- int *formal_charge = new int[mol.NumAtoms()];
- int i;
-
- i = 0;
- FOR_ATOMS_OF_MOL (atom, mol) {
- formal_charge[i] = atom->GetFormalCharge();
- ++i;
- }
_mol = mol;
- i = 0;
- FOR_ATOMS_OF_MOL (atom, _mol) {
- atom->SetFormalCharge(formal_charge[i]);
- ++i;
- }
- delete [] formal_charge;
_ncoords = _mol.NumAtoms() * 3;
if (_velocityPtr)
--- 856,862 ----
***************
*** 925,945 ****
}
if (IsSetupNeeded(mol)) {
- int *formal_charge = new int[mol.NumAtoms()];
- int i;
-
- i = 0;
- FOR_ATOMS_OF_MOL (atom, mol) {
- formal_charge[i] = atom->GetFormalCharge();
- ++i;
- }
_mol = mol;
- i = 0;
- FOR_ATOMS_OF_MOL (atom, _mol) {
- atom->SetFormalCharge(formal_charge[i]);
- ++i;
- }
- delete [] formal_charge;
_ncoords = _mol.NumAtoms() * 3;
if (_velocityPtr)
--- 912,918 ----
*** src/data.cpp.orig 2012-05-18 01:04:55.818907112 +0200
--- src/data.cpp 2012-05-18 01:05:05.358819367 +0200
***************
*** 568,576 ****
string sto,sfrom;
sfrom = from;
rval = Translate(sto,sfrom);
! strncpy(to,(char*)sto.c_str(), sizeof(to) - 1);
! to[sizeof(to) - 1] = '\0';
!
return(rval);
}
--- 568,576 ----
string sto,sfrom;
sfrom = from;
rval = Translate(sto,sfrom);
! strncpy(to,(char*)sto.c_str(), OBATOM_TYPE_LEN - 1);
! to[OBATOM_TYPE_LEN - 1] = '\0';
!
return(rval);
}
*** include/openbabel/atom.h.orig 2012-05-18 00:20:06.932510403 +0200
--- include/openbabel/atom.h 2012-05-18 00:55:56.804975387 +0200
***************
*** 77,88 ****
// Class OBAtom
// class introduction in atom.cpp
class OBAPI OBAtom: public OBBase
{
protected:
unsigned char _ele; //!< atomic number (type
unsigned char to minimize space -- allows for 0..255 elements)
char _impval; //!< implicit valence
! char _type[6]; //!< atomic type
short _fcharge; //!< formal charge
unsigned short _isotope; //!< isotope (0 = most
abundant)
short _spinmultiplicity;//!< atomic spin, e.g.,
2 for radical 1 or 3 for carbene
--- 77,89 ----
// Class OBAtom
// class introduction in atom.cpp
+ #define OBATOM_TYPE_LEN 6
class OBAPI OBAtom: public OBBase
{
protected:
unsigned char _ele; //!< atomic number (type
unsigned char to minimize space -- allows for 0..255 elements)
char _impval; //!< implicit valence
! char _type[OBATOM_TYPE_LEN]; //!< atomic type
short _fcharge; //!< formal charge
unsigned short _isotope; //!< isotope (0 = most
abundant)
short _spinmultiplicity;//!< atomic spin, e.g.,
2 for radical 1 or 3 for carbene
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss