Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
vala
vala
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 702
    • Issues 702
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 38
    • Merge Requests 38
  • Operations
    • Operations
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • GNOME
  • valavala
  • Issues
  • #471

Closed
Open
Opened Aug 17, 2014 by bugzilla-migration@bugzilla-migrationReporter

Accessing a fixed-size array in a struct will copy the struct

Submitted by naxuroqa @naxuroqa

Link to original bug (#734957)

Description

struct Options { uint8 data[256]; }

int main(string[] args) { Options options = Options(); string foo = "hello, world"; Memory.copy(options.data, foo, foo.length); return 0; }

results in

... gint _vala_main (gchar** args, int args_length1) { gint result = 0; Options options = {0}; gchar* foo = NULL; gchar* tmp0 = NULL; Options tmp1 = {0}; gint tmp2 = 0; gint tmp3 = 0; memset (&options, 0, sizeof (Options)); tmp0 = g_strdup ("hello, world"); foo = tmp0; tmp1 = options; tmp2 = strlen (foo); tmp3 = tmp2; memcpy (tmp1.data, foo, (gsize) tmp3); result = 0; _g_free0 (foo); return result; } ...

Which copies the struct and memcpys to the duplicate.

Memory.copy(*(&options.data), foo, foo.length);

does the right, but seems to me like a terrible workaround.

Version: 0.24.x

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: GNOME/vala#471