diff options
Diffstat (limited to 'libs')
24 files changed, 68 insertions, 52 deletions
diff --git a/libs/androidfw/Asset.cpp b/libs/androidfw/Asset.cpp index 4e14b13dc8bd..2cfa6666e9ab 100644 --- a/libs/androidfw/Asset.cpp +++ b/libs/androidfw/Asset.cpp @@ -69,7 +69,7 @@ String8 Asset::getAssetAllocations() res.append(cur->getAssetSource()); off64_t size = (cur->getLength()+512)/1024; char buf[64]; - sprintf(buf, ": %dK\n", (int)size); + snprintf(buf, sizeof(buf), ": %dK\n", (int)size); res.append(buf); } cur = cur->mNext; diff --git a/libs/androidfw/BackupHelpers.cpp b/libs/androidfw/BackupHelpers.cpp index 9300794cf310..78e9d91c4d67 100644 --- a/libs/androidfw/BackupHelpers.cpp +++ b/libs/androidfw/BackupHelpers.cpp @@ -442,7 +442,7 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD return 0; } -static void calc_tar_checksum(char* buf) { +static void calc_tar_checksum(char* buf, size_t buf_size) { // [ 148 : 8 ] checksum -- to be calculated with this field as space chars memset(buf + 148, ' ', 8); @@ -453,11 +453,13 @@ static void calc_tar_checksum(char* buf) { // Now write the real checksum value: // [ 148 : 8 ] checksum: 6 octal digits [leading zeroes], NUL, SPC - sprintf(buf + 148, "%06o", sum); // the trailing space is already in place + snprintf(buf + 148, buf_size - 148, "%06o", sum); // the trailing space is + // already in place } // Returns number of bytes written -static int write_pax_header_entry(char* buf, const char* key, const char* value) { +static int write_pax_header_entry(char* buf, size_t buf_size, + const char* key, const char* value) { // start with the size of "1 key=value\n" int len = strlen(key) + strlen(value) + 4; if (len > 9) len++; @@ -466,7 +468,7 @@ static int write_pax_header_entry(char* buf, const char* key, const char* value) // since PATH_MAX is 4096 we don't expect to have to generate any single // header entry longer than 9999 characters - return sprintf(buf, "%d %s=%s\n", len, key, value); + return snprintf(buf, buf_size, "%d %s=%s\n", len, key, value); } // Wire format to the backup manager service is chunked: each chunk is prefixed by @@ -550,8 +552,12 @@ int write_tarfile(const String8& packageName, const String8& domain, // read/write up to this much at a time. const size_t BUFSIZE = 32 * 1024; char* buf = (char *)calloc(1,BUFSIZE); - char* paxHeader = buf + 512; // use a different chunk of it as separate scratch - char* paxData = buf + 1024; + const size_t PAXHEADER_OFFSET = 512; + const size_t PAXHEADER_SIZE = 512; + const size_t PAXDATA_SIZE = BUFSIZE - (PAXHEADER_SIZE + PAXHEADER_OFFSET); + char* const paxHeader = buf + PAXHEADER_OFFSET; // use a different chunk of + // it as separate scratch + char* const paxData = paxHeader + PAXHEADER_SIZE; if (buf == NULL) { ALOGE("Out of mem allocating transfer buffer"); @@ -630,21 +636,21 @@ int write_tarfile(const String8& packageName, const String8& domain, // already preflighted if (needExtended) { char sizeStr[32]; // big enough for a 64-bit unsigned value in decimal - char* p = paxData; // construct the pax extended header data block - memset(paxData, 0, BUFSIZE - (paxData - buf)); + memset(paxData, 0, PAXDATA_SIZE); // size header -- calc len in digits by actually rendering the number // to a string - brute force but simple + int paxLen = 0; snprintf(sizeStr, sizeof(sizeStr), "%lld", (long long)s.st_size); - p += write_pax_header_entry(p, "size", sizeStr); + paxLen += write_pax_header_entry(paxData, PAXDATA_SIZE, "size", sizeStr); // fullname was generated above with the ustar paths - p += write_pax_header_entry(p, "path", fullname.string()); + paxLen += write_pax_header_entry(paxData + paxLen, PAXDATA_SIZE - paxLen, + "path", fullname.string()); // Now we know how big the pax data is - int paxLen = p - paxData; // Now build the pax *header* templated on the ustar header memcpy(paxHeader, buf, 512); @@ -659,10 +665,10 @@ int write_tarfile(const String8& packageName, const String8& domain, // [ 124 : 12 ] size of pax extended header data memset(paxHeader + 124, 0, 12); - snprintf(paxHeader + 124, 12, "%011o", (unsigned int)(p - paxData)); + snprintf(paxHeader + 124, 12, "%011o", (unsigned int)paxLen); // Checksum and write the pax block header - calc_tar_checksum(paxHeader); + calc_tar_checksum(paxHeader, PAXHEADER_SIZE); send_tarfile_chunk(writer, paxHeader, 512); // Now write the pax data itself @@ -671,7 +677,7 @@ int write_tarfile(const String8& packageName, const String8& domain, } // Checksum and write the 512-byte ustar file header block to the output - calc_tar_checksum(buf); + calc_tar_checksum(buf, BUFSIZE); send_tarfile_chunk(writer, buf, 512); // Now write the file data itself, for real files. We honor tar's convention that diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index ceeb12bab205..44486774a0f2 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -3116,7 +3116,7 @@ String8 ResTable_config::toString() const { struct ResTable::Header { - Header(ResTable* _owner) : owner(_owner), ownedData(NULL), header(NULL), + explicit Header(ResTable* _owner) : owner(_owner), ownedData(NULL), header(NULL), resourceIDMap(NULL), resourceIDMapSize(0) { } ~Header() @@ -6759,7 +6759,7 @@ bool ResTable::getIdmapInfo(const void* idmap, size_t sizeBytes, #define CHAR16_TO_CSTR(c16, len) (String8(String16(c16,len)).string()) #define CHAR16_ARRAY_EQ(constant, var, len) \ - ((len == (sizeof(constant)/sizeof(constant[0]))) && (0 == memcmp((var), (constant), (len)))) + (((len) == (sizeof(constant)/sizeof((constant)[0]))) && (0 == memcmp((var), (constant), (len)))) static void print_complex(uint32_t complex, bool isFraction) { diff --git a/libs/androidfw/ZipUtils.cpp b/libs/androidfw/ZipUtils.cpp index 6fa0f14ecb8e..5abfc8ee917e 100644 --- a/libs/androidfw/ZipUtils.cpp +++ b/libs/androidfw/ZipUtils.cpp @@ -150,7 +150,7 @@ bail: class FileReader { public: - FileReader(FILE* fp) : + explicit FileReader(FILE* fp) : mFp(fp), mReadBuf(new unsigned char[kReadBufSize]) { } @@ -170,7 +170,7 @@ public: class FdReader { public: - FdReader(int fd) : + explicit FdReader(int fd) : mFd(fd), mReadBuf(new unsigned char[kReadBufSize]) { } diff --git a/libs/common_time/common_time_server_api.cpp b/libs/common_time/common_time_server_api.cpp index e0f35a9def8b..60e65677b2f9 100644 --- a/libs/common_time/common_time_server_api.cpp +++ b/libs/common_time/common_time_server_api.cpp @@ -285,7 +285,7 @@ void CommonTimeServer::reevaluateAutoDisableState(bool commonClockHasClients) { if (res > 0) \ write(fd, buffer, res); \ } while (0) -#define checked_percentage(a, b) ((0 == b) ? 0.0f : ((100.0f * a) / b)) +#define checked_percentage(a, b) ((0 == (b)) ? 0.0f : ((100.0f * (a)) / (b))) status_t CommonTimeServer::dumpClockInterface(int fd, const Vector<String16>& /* args */, diff --git a/libs/common_time/common_time_server_packets.cpp b/libs/common_time/common_time_server_packets.cpp index 9833c37f2519..c7c893d34499 100644 --- a/libs/common_time/common_time_server_packets.cpp +++ b/libs/common_time/common_time_server_packets.cpp @@ -48,12 +48,12 @@ const uint16_t TimeServicePacketHeader::kCurVersion = 1; #define SERIALIZE_INT32(field_name) SERIALIZE_FIELD(field_name, int32_t, htonl) #define SERIALIZE_INT64(field_name) SERIALIZE_FIELD(field_name, int64_t, htonq) -#define DESERIALIZE_FIELD(field_name, type, converter) \ - do { \ - if ((offset + sizeof(field_name)) > length) \ - return -1; \ - field_name = converter(*((type*)(data + offset))); \ - offset += sizeof(field_name); \ +#define DESERIALIZE_FIELD(field_name, type, converter) \ + do { \ + if ((offset + sizeof(field_name)) > length) \ + return -1; \ + (field_name) = converter(*((type*)(data + offset))); \ + offset += sizeof(field_name); \ } while (0) #define DESERIALIZE_INT16(field_name) DESERIALIZE_FIELD(field_name, int16_t, ntohs) #define DESERIALIZE_INT32(field_name) DESERIALIZE_FIELD(field_name, int32_t, ntohl) diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index c9d4af69c0df..5dcfa4e102fd 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -181,7 +181,6 @@ LOCAL_SRC_FILES := $(hwui_src_files) LOCAL_C_INCLUDES := $(hwui_c_includes) $(call hwui_proto_include) LOCAL_EXPORT_C_INCLUDE_DIRS := \ $(LOCAL_PATH) \ - $(hwui_c_includes) \ $(call hwui_proto_include) include $(LOCAL_PATH)/hwui_static_deps.mk @@ -205,7 +204,6 @@ LOCAL_SRC_FILES := \ LOCAL_C_INCLUDES := $(hwui_c_includes) $(call hwui_proto_include) LOCAL_EXPORT_C_INCLUDE_DIRS := \ $(LOCAL_PATH) \ - $(hwui_c_includes) \ $(call hwui_proto_include) include $(LOCAL_PATH)/hwui_static_deps.mk @@ -238,6 +236,7 @@ LOCAL_SHARED_LIBRARIES := libmemunreachable LOCAL_CFLAGS := \ $(hwui_cflags) \ -DHWUI_NULL_GPU +LOCAL_C_INCLUDES := $(hwui_c_includes) LOCAL_SRC_FILES += \ $(hwui_test_common_src_files) \ @@ -293,6 +292,7 @@ LOCAL_MULTILIB := both LOCAL_MODULE_STEM_32 := hwuitest LOCAL_MODULE_STEM_64 := hwuitest64 LOCAL_CFLAGS := $(hwui_cflags) +LOCAL_C_INCLUDES := $(hwui_c_includes) # set to libhwui_static_null_gpu to skip actual GL commands LOCAL_WHOLE_STATIC_LIBRARIES := libhwui_static @@ -321,6 +321,8 @@ LOCAL_CFLAGS := \ $(hwui_cflags) \ -DHWUI_NULL_GPU +LOCAL_C_INCLUDES := $(hwui_c_includes) + LOCAL_WHOLE_STATIC_LIBRARIES := libhwui_static_null_gpu LOCAL_STATIC_LIBRARIES := libgoogle-benchmark diff --git a/libs/hwui/AnimatorManager.cpp b/libs/hwui/AnimatorManager.cpp index f170e9cda8af..9d5860ca0d1a 100644 --- a/libs/hwui/AnimatorManager.cpp +++ b/libs/hwui/AnimatorManager.cpp @@ -168,7 +168,7 @@ void AnimatorManager::endAllStagingAnimators() { class EndActiveAnimatorsFunctor { public: - EndActiveAnimatorsFunctor(AnimationContext& context) : mContext(context) {} + explicit EndActiveAnimatorsFunctor(AnimationContext& context) : mContext(context) {} void operator() (sp<BaseRenderNodeAnimator>& animator) { animator->forceEndNow(mContext); diff --git a/libs/hwui/DeferredDisplayList.cpp b/libs/hwui/DeferredDisplayList.cpp index 1b0f42466bff..689179dd8fb4 100644 --- a/libs/hwui/DeferredDisplayList.cpp +++ b/libs/hwui/DeferredDisplayList.cpp @@ -62,7 +62,7 @@ public: class DrawBatch : public Batch { public: - DrawBatch(const DeferInfo& deferInfo) : mAllOpsOpaque(true), + explicit DrawBatch(const DeferInfo& deferInfo) : mAllOpsOpaque(true), mBatchId(deferInfo.batchId), mMergeId(deferInfo.mergeId) { mOps.clear(); } diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h index 59f073ff593c..2a859132e783 100644 --- a/libs/hwui/DisplayListOp.h +++ b/libs/hwui/DisplayListOp.h @@ -621,8 +621,8 @@ public: } #define SET_TEXTURE(ptr, posRect, offsetRect, texCoordsRect, xDim, yDim) \ - TextureVertex::set(ptr++, posRect.xDim - offsetRect.left, posRect.yDim - offsetRect.top, \ - texCoordsRect.xDim, texCoordsRect.yDim) + TextureVertex::set((ptr)++, (posRect).xDim - (offsetRect).left, (posRect).yDim - (offsetRect).top, \ + (texCoordsRect).xDim, (texCoordsRect).yDim) /** * This multi-draw operation builds a mesh on the stack by generating a quad diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp index 709156c4098b..a936661f86f9 100644 --- a/libs/hwui/Matrix.cpp +++ b/libs/hwui/Matrix.cpp @@ -419,7 +419,7 @@ void Matrix4::mapPoint3d(Vector3& vec) const { vec.z = orig.x * data[2] + orig.y * data[6] + orig.z * data[kScaleZ] + data[kTranslateZ]; } -#define MUL_ADD_STORE(a, b, c) a = (a) * (b) + (c) +#define MUL_ADD_STORE(a, b, c) ((a) = (a) * (b) + (c)) void Matrix4::mapPoint(float& x, float& y) const { if (isSimple()) { diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index b68240ac7519..9d821f38fab6 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -838,7 +838,7 @@ void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect) { */ #define DRAW_DOUBLE_STENCIL_IF(COND, DRAW_COMMAND) { \ DRAW_COMMAND; \ - if (CC_UNLIKELY(Properties::debugOverdraw && getTargetFbo() == 0 && COND)) { \ + if (CC_UNLIKELY(Properties::debugOverdraw && getTargetFbo() == 0 && (COND))) { \ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); \ DRAW_COMMAND; \ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); \ diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index 171873de1f9a..8fec42972c2f 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -224,9 +224,9 @@ enum DebugLevel { /////////////////////////////////////////////////////////////////////////////// // Converts a number of mega-bytes into bytes -#define MB(s) s * 1024 * 1024 +#define MB(s) ((s) * 1024 * 1024) // Converts a number of kilo-bytes into bytes -#define KB(s) s * 1024 +#define KB(s) ((s) * 1024) enum class ProfileType { None, diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h index 47fef6da355c..f9735a231d7a 100644 --- a/libs/hwui/RenderNode.h +++ b/libs/hwui/RenderNode.h @@ -146,7 +146,7 @@ public: void setName(const char* name) { if (name) { - char* lastPeriod = strrchr(name, '.'); + const char* lastPeriod = strrchr(name, '.'); if (lastPeriod) { mName.setTo(lastPeriod + 1); } else { diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h index 395279806adb..6a6e8dbb3fcd 100644 --- a/libs/hwui/RenderProperties.h +++ b/libs/hwui/RenderProperties.h @@ -47,7 +47,7 @@ class RenderNode; class RenderProperties; // The __VA_ARGS__ will be executed if a & b are not equal -#define RP_SET(a, b, ...) (a != b ? (a = b, ##__VA_ARGS__, true) : false) +#define RP_SET(a, b, ...) ((a) != (b) ? ((a) = (b), ##__VA_ARGS__, true) : false) #define RP_SET_AND_DIRTY(a, b) RP_SET(a, b, mPrimitiveFields.mMatrixOrPivotDirty = true) // Keep in sync with View.java:LAYER_TYPE_* diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index ce67554645d1..0693804d5770 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -208,7 +208,7 @@ SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) { class ClipCopier : public SkCanvas::ClipVisitor { public: - ClipCopier(SkCanvas* dstCanvas) : m_dstCanvas(dstCanvas) {} + explicit ClipCopier(SkCanvas* dstCanvas) : m_dstCanvas(dstCanvas) {} virtual void clipRect(const SkRect& rect, SkRegion::Op op, bool antialias) { m_dstCanvas->clipRect(rect, op, antialias); diff --git a/libs/hwui/TessellationCache.cpp b/libs/hwui/TessellationCache.cpp index cfdc0848c8b0..d9e811684610 100644 --- a/libs/hwui/TessellationCache.cpp +++ b/libs/hwui/TessellationCache.cpp @@ -136,7 +136,7 @@ public: class TessellationCache::TessellationProcessor : public TaskProcessor<VertexBuffer*> { public: - TessellationProcessor(Caches& caches) + explicit TessellationProcessor(Caches& caches) : TaskProcessor<VertexBuffer*>(&caches.tasks) {} ~TessellationProcessor() {} @@ -150,7 +150,7 @@ public: class TessellationCache::Buffer { public: - Buffer(const sp<Task<VertexBuffer*> >& task) + explicit Buffer(const sp<Task<VertexBuffer*> >& task) : mTask(task) , mBuffer(nullptr) { } @@ -270,7 +270,7 @@ void tessellateShadows( class ShadowProcessor : public TaskProcessor<TessellationCache::vertexBuffer_pair_t> { public: - ShadowProcessor(Caches& caches) + explicit ShadowProcessor(Caches& caches) : TaskProcessor<TessellationCache::vertexBuffer_pair_t>(&caches.tasks) {} ~ShadowProcessor() {} diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp index 8ba4761c1b2e..fcdde45c49f2 100644 --- a/libs/hwui/font/CacheTexture.cpp +++ b/libs/hwui/font/CacheTexture.cpp @@ -188,15 +188,21 @@ void CacheTexture::allocatePixelBuffer() { bool CacheTexture::upload() { const Rect& dirtyRect = mDirtyRect; - uint32_t x = mHasUnpackRowLength ? dirtyRect.left : 0; - uint32_t y = dirtyRect.top; - uint32_t width = mHasUnpackRowLength ? dirtyRect.getWidth() : getWidth(); - uint32_t height = dirtyRect.getHeight(); + // align the x direction to 32 and y direction to 4 for better performance + uint32_t x = (((uint32_t)dirtyRect.left) & (~0x1F)); + uint32_t y = (((uint32_t)dirtyRect.top) & (~0x3)); + uint32_t r = ((((uint32_t)dirtyRect.right) + 0x1F) & (~0x1F)) - x; + uint32_t b = ((((uint32_t)dirtyRect.bottom) + 0x3) & (~0x3)) - y; + uint32_t width = (r > getWidth() ? getWidth() : r); + uint32_t height = (b > getHeight() ? getHeight() : b); // The unpack row length only needs to be specified when a new // texture is bound if (mHasUnpackRowLength) { glPixelStorei(GL_UNPACK_ROW_LENGTH, getWidth()); + } else { + x = 0; + width = getWidth(); } mPixelBuffer->upload(x, y, width, height); diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp index e78cd7296f42..5e600644ca19 100644 --- a/libs/hwui/renderstate/RenderState.cpp +++ b/libs/hwui/renderstate/RenderState.cpp @@ -211,7 +211,7 @@ void RenderState::debugOverdraw(bool enable, bool clear) { class DecStrongTask : public renderthread::RenderTask { public: - DecStrongTask(VirtualLightRefBase* object) : mObject(object) {} + explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {} virtual void run() override { mObject->decStrong(nullptr); diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 9fb30c928c00..3c1c0bceba58 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -128,7 +128,7 @@ class DispatchFrameCallbacks : public RenderTask { private: RenderThread* mRenderThread; public: - DispatchFrameCallbacks(RenderThread* rt) : mRenderThread(rt) {} + explicit DispatchFrameCallbacks(RenderThread* rt) : mRenderThread(rt) {} virtual void run() override { mRenderThread->dispatchFrameCallbacks(); diff --git a/libs/hwui/utils/LinearAllocator.cpp b/libs/hwui/utils/LinearAllocator.cpp index 5bba420a258f..d92bc0cd1fca 100644 --- a/libs/hwui/utils/LinearAllocator.cpp +++ b/libs/hwui/utils/LinearAllocator.cpp @@ -48,8 +48,8 @@ #define ALIGN_SZ (sizeof(int)) #endif -#define ALIGN(x) ((x + ALIGN_SZ - 1 ) & ~(ALIGN_SZ - 1)) -#define ALIGN_PTR(p) ((void*)(ALIGN((size_t)p))) +#define ALIGN(x) (((x) + ALIGN_SZ - 1 ) & ~(ALIGN_SZ - 1)) +#define ALIGN_PTR(p) ((void*)(ALIGN((size_t)(p)))) #if LOG_NDEBUG #define ADD_ALLOCATION() diff --git a/libs/storage/Android.mk b/libs/storage/Android.mk index fae2bf7c3457..d0eb6d4eb425 100644 --- a/libs/storage/Android.mk +++ b/libs/storage/Android.mk @@ -11,4 +11,6 @@ LOCAL_MODULE:= libstorage LOCAL_CFLAGS += -Wall -Werror +LOCAL_SHARED_LIBRARIES := libbinder + include $(BUILD_STATIC_LIBRARY) diff --git a/libs/storage/IMountService.cpp b/libs/storage/IMountService.cpp index c643ed008a3b..74638e7eccc3 100644 --- a/libs/storage/IMountService.cpp +++ b/libs/storage/IMountService.cpp @@ -55,7 +55,7 @@ enum { class BpMountService: public BpInterface<IMountService> { public: - BpMountService(const sp<IBinder>& impl) + explicit BpMountService(const sp<IBinder>& impl) : BpInterface<IMountService>(impl) { } diff --git a/libs/storage/IObbActionListener.cpp b/libs/storage/IObbActionListener.cpp index 9656e655e22c..a71341bc1364 100644 --- a/libs/storage/IObbActionListener.cpp +++ b/libs/storage/IObbActionListener.cpp @@ -26,7 +26,7 @@ enum { // This is a stub that real consumers should override. class BpObbActionListener: public BpInterface<IObbActionListener> { public: - BpObbActionListener(const sp<IBinder>& impl) + explicit BpObbActionListener(const sp<IBinder>& impl) : BpInterface<IObbActionListener>(impl) { } |