Date: Sun, 26 May 2019 07:02:52 -0700 From: Enji Cooper <yaneurabeya@gmail.com> To: Alan Somers <asomers@freebsd.org> Cc: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: Re: svn commit: r348285 - projects/fuse2/tests/sys/fs/fusefs Message-ID: <276AB18D-F1C7-47FF-B070-A019352FB615@gmail.com> In-Reply-To: <201905260352.x4Q3qZBT010750@repo.freebsd.org> References: <201905260352.x4Q3qZBT010750@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> On May 25, 2019, at 20:52, Alan Somers <asomers@freebsd.org> wrote: >=20 > Author: asomers > Date: Sun May 26 03:52:35 2019 > New Revision: 348285 > URL: https://svnweb.freebsd.org/changeset/base/348285 >=20 > Log: > fusefs: more build fixes >=20 > * Fix printf format strings on 32-bit OSes > * Fix -Wclass-memaccess violation on GCC-8 caused by using memset on an o= bject > of non-trivial type. > * Fix memory leak in MockFS::init > * Fix -Wcast-align error on i386 in expect_readdir > * Fix some heterogenous comparison errors on 32-bit OSes. >=20 > Sponsored by: The FreeBSD Foundation >=20 > Modified: > projects/fuse2/tests/sys/fs/fusefs/mockfs.cc > projects/fuse2/tests/sys/fs/fusefs/mockfs.hh > projects/fuse2/tests/sys/fs/fusefs/read.cc > projects/fuse2/tests/sys/fs/fusefs/setattr.cc > projects/fuse2/tests/sys/fs/fusefs/utils.cc >=20 > Modified: projects/fuse2/tests/sys/fs/fusefs/mockfs.cc > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > --- projects/fuse2/tests/sys/fs/fusefs/mockfs.cc Sat May 25 23:58:09 20= 19 (r348284) > +++ projects/fuse2/tests/sys/fs/fusefs/mockfs.cc Sun May 26 03:52:35 20= 19 (r348285) ... > - in =3D (mockfs_buf_in*) malloc(sizeof(*in)); > + in =3D new mockfs_buf_in; > ASSERT_TRUE(in !=3D NULL); > - out =3D (mockfs_buf_out*) malloc(sizeof(*out)); > + out =3D new mockfs_buf_out; > ASSERT_TRUE(out !=3D NULL); >=20 > read_request(in); > ASSERT_EQ(FUSE_INIT, in->header.opcode); >=20 > - memset(out, 0, sizeof(*out)); > out->header.unique =3D in->header.unique; > out->header.error =3D 0; > out->body.init.major =3D FUSE_KERNEL_VERSION; > @@ -418,7 +423,8 @@ void MockFS::init(uint32_t flags) { > SET_OUT_HEADER_LEN(out, init); > write(m_fuse_fd, out, out->header.len); >=20 > - free(in); > + delete out; > + delete in; Given that the tests are currently using C++14, it seems like it would make s= ense to use smart pointers here to manage the scope/lifetime of the objects,= as this could leak if someone added an early return or an exception was thr= own. Ref: https://en.cppreference.com/book/intro/smart_pointers. > } >=20 > void MockFS::kill_daemon() { >=20 > Modified: projects/fuse2/tests/sys/fs/fusefs/mockfs.hh > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > --- projects/fuse2/tests/sys/fs/fusefs/mockfs.hh Sat May 25 23:58:09 20= 19 (r348284) > +++ projects/fuse2/tests/sys/fs/fusefs/mockfs.hh Sun May 26 03:52:35 20= 19 (r348285) > @@ -166,7 +166,7 @@ union fuse_payloads_out { > fuse_create_out create; > fuse_create_out_7_8 create_7_8; > /* The protocol places no limits on the size of bytes */ > - uint8_t bytes[0x20000]; > + uint8_t bytes[0x20000]; What does this hex value represent? Could it be made into a constant? ... > - cur_size =3D std::max(cur_size, > + cur_size =3D std::max((uint64_t)cur_size, > in->body.write.size + in->body.write.offset); > }))); Casting like this is legal, but this is the C way of doing casting. C++11 an= d newer recommends using static_cast for all compile time casting and dynami= c_cast for all runtime casting. Thanks :)! -Enji=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?276AB18D-F1C7-47FF-B070-A019352FB615>